#include "stdio.h"
#include "stdlib.h"
//prvi zad.
long long sum=0;
int *a;

void funk(int w,int q, int k){
     int max=a[w],maxi=w,i;
     for(i=w+1;i<=q;i++) if (a[i]>max) {max=a[i];maxi=i;}
     sum+=k-max;
     if(maxi>w) funk(w,maxi-1,max);
     if(maxi<q) funk(maxi+1,q,max);          
}

int main(){
FILE *in=fopen("zetoni.in","r"),*out=fopen("zetoni.out","w");

     int n,k,i;
     fscanf(in,"%d %d",&n,&k);
     a=(int *)malloc(n*sizeof(int));
     for(i=0;i<n;i++) fscanf(in,"%d",a+i);
     funk(0,n-1,k);
     fprintf(out,"%lld\n",sum);
    
fclose(in);fclose(out);return 0;
}
