#include <stdio.h>
static bool p[1000000];
static long long a[1000000],br,k,n;

void potez(long long l,long long d)
 {long long brk,i;
   bool ok=true;
  if (d-l>=0 && d<n)
    { for(i=l;i<=d;i++)
        if(p[i])
        {potez(l,i-1);
         potez(i+1,d);
         ok=false;
         break;
         }
      if (ok){ brk=l;
               for(i=l+1;i<=d;i++)
                  if (a[brk]<a[i])brk=i;
                brk=k-a[brk];  
                br+=brk;
               for(i=l;i<=d;i++)
                 {a[i]+=brk;
                  p[i]=(  a[i]==k);
                  } 
                 potez(l,d);              
               }
              
              
     }
 }

int main()
{
  FILE *in,*out;
  in=fopen("zetoni.in","r");
  out=fopen("zetoni.out","w");  
long long i;
fscanf(in,"%lld%lld",&n,&k);
for(i=0;i<n;i++)
 {fscanf(in,"%lld",&a[i]);
     p[i]=(a[i]==k);
 }
potez(0,n-1);
fprintf(out,"%lld",br);

fclose(in);
fclose(out);



}
