// resenje koje prolazi skroz:
//   uraditi segmentno gde su cvorovi
//   vektori pozicija max elemenata
//   u tom intervalu; dalje slicno kao
//   ovo ispod...

#include <cstdio>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>

using namespace std;

const int maxN = 1000005;
const int tmp = 17005;

int max (int a, int b) {
    if (a > b)
        return a;
    else
        return b;
}
/*
void segment (int first, int last, int curr) { //cout << first << " " << last << " " << curr << endl;
    if (first == last) {
        m[curr] = a[first];
  // m[curr] = 5;
    }
    else {
        int mid = (first + last) / 2;

        segment(first, mid, 2*curr);
        segment(mid+1, last, 2*curr+1);
        //cout << "MAX: " << max( m[2*curr], m[2*curr+1] ) << endl;
        m[curr] = max( m[2*curr], m[2*curr+1] );
    }
}
*/
/*
int qqq (int p, int q, int first, int last, int curr) {
    if ( p >= first && last <= q ) {
        return m[curr];
    }

    if ( q < first || p > last )
        return -1;

    if ( first <= p && q <= last ) {
        int mid = (first + last) / 2;
        return max( qqq(p, q, first, mid, 2*curr), qqq(p, q, mid+1, last, 2*curr+1) );
    }

    if ( p <= first && first <= q)
        return qqq(first, q, first, last, curr);
    if ( p <= last && last <= q )
        return qqq(p, last, first, last, curr);
}
*/

int n, k;
//int a[maxN], m[2*maxN];
int a[maxN], d[tmp][tmp];

void init () {
    for (int i = 1; i <= n; ++i)
        d[i][i] = a[i];
    for (int i = 1; i <= n; ++i)
        for (int j = i+1; j <= n; ++j)
            d[i][j] = max( d[i][j-1], a[j] );
}

long long equalise (int p, int q, int val) {
    if ( p >= q )
        return 0;

    long long ret = 0;
    int idx = p;

    while (a[idx] != val)
        idx++;

    if ( p <= idx - 1 )
        ret += equalise(p, idx-1, d[p][idx-1]) + (val - d[p][idx-1]);
    if ( idx+1 <= q )
        ret += equalise(idx+1, q, d[idx+1][q]) + (val - d[idx+1][q]);

    return ret;
}

int main () {
    freopen("zetoni.in", "r", stdin);
    freopen("zetoni.out", "w", stdout);

    scanf("%d%d", &n, &k);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &a[i]);
    }

    init();
 /*   for (int i = 1; i <= n; ++i)
        for (int j = i; j <= n; ++j)
            cout << "max[" << i << "," << j << "]: " << d[i][j] << endl;
            */
    long long sol = equalise(1, n, d[1][n]) + (k - d[1][n]);
    cout << sol << endl;

    //system("PAUSE");
    return 0;
}

