#include <cstdlib>
#include <iostream>
#include <stdio.h>

using namespace std;

long long n,k;

int main(int argc, char *argv[])
{
    FILE *in;
    FILE *out;
    in=fopen("zetoni.in","r");
    out=fopen("zetoni.out","w");
    fscanf(in,"%d",&n);
    fscanf(in,"%d",&k);
    long long total=0,current=0,prev=0;
    for(int i=0; i<n; i++)
     {
         long long x;
         fscanf(in,"%lld",&x);
         x=k-x;
         if(x>current)
          {
              total+=x-current;
              current=max(current,x-current);
          }
         else
          {
              current=x;
          }
         //printf("%lld %lld\n",current,x);
     }
    fprintf(out,"%lld\n",total);
    fclose(in);
    fclose(out);
    system("PAUSE");
    return 0;
}
