#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<queue>
#include<deque>
#include<algorithm>
#include<utility>
#include<stack>
#include<set>
#include<cstring>
#include<vector>
using namespace std;



long long int SOL=0;
int n,k;
int a[123456];

void BRUTE(int L,int R,int DIFF)
{
   if (R-L!=1)
   
   {
        int MAX=-1;
        int POZ=-1;
        for (int i=L+1;i<R;i++) a[i]+=DIFF;
        for (int i=L+1;i<R;i++)
   {
        if (a[i]>MAX) 
        {
        POZ=i;
        MAX=a[i];
        }
    } 
    SOL+=(k-MAX);
    DIFF=k-MAX;
    BRUTE(L,POZ,DIFF);
    BRUTE(POZ,R,DIFF);
}
}


int main()
{
    freopen("zetoni.in","r",stdin);
    freopen("zetoni.out","w",stdout);
    scanf("%d %d",&n,&k);
    a[0]=k;
    a[n+1]=k;
 for (int i=1;i<=n;i++) scanf("%d",&a[i]);
 BRUTE(1,n+1,0);
 cout<<SOL<<endl;

 
 return 0;   
}
