#include <iostream>
#include <cstdio>
#include <vector>

using namespace std;

long long data[1000000];

struct interval
{
       int l,r;
};

long long maxp(int i, int j)
{
    long long tmax = -1;
    while(i<=j)
    {
               if(data[i]>tmax) tmax = data[i];
               i++;
    }
    return tmax;
}

vector<interval> next;
vector<interval> hv;

long long calc(long long k)
{
     int res = 0;
     while(next.size()>0)
     {
                         for(int i=0;i<next.size();i++)
                         {
                                 long long m = maxp(next[i].l,next[i].r);
                                 res+=k-m;
                                 interval d;
                                 d.l=0;
                                 for(int j=next[i].l;j<=next[i].r;j++)
                                 {
                                         data[j]+=k-m;
                                         if(data[j]==k)
                                         {
                                                       if(j!=next[i].l)
                                                       {
                                                               d.r = j-1;
                                                               hv.push_back(d);
                                                       }
                                                       d.l = j+1;
                                         }
                                 }
                                 if(data[next[i].r]!=k)
                                 {
                                                        d.r = next[i].r;
                                                        hv.push_back(d);
                                 }
                         }
                         next.clear();
                         next = hv;
                         hv.clear();
     }
     return res;
}

int main()
{
    int n;
    int k;
    int res = 0;
    FILE* infile = fopen("zetoni.in","r");
    fscanf(infile, "%d", &n);
    fscanf(infile, "%lld", &k);
    for(int i=0;i<n;i++)
    {
            fscanf(infile, "%lld", &data[i]);
    }
    fclose(infile);
    interval d1;
    d1.l=0;
    d1.r=n-1;
    next.push_back(d1);
    res = calc(k);
    FILE* outfile = fopen("zetoni.out","w");
    fprintf(outfile, "%lld", res);
    fclose(outfile);
    return 0;
}
