#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int A[1000005],N,K;
int Stek[1000005],Sh,i,j,k,l,najveci;
long long sol;

int main(){
   //freopen("zetoni.in","r",stdin);
   //freopen("zetoni.out","w",stdout);
   scanf("%d%d",&N,&K);
   A[1] = K;
   A[N+2] = K;
   for (i=2; i<=N+1; i++) scanf("%d",A+i);
   for (i=1; i<=N+2; i++){
      if (A[i] > Stek[Sh] && Sh>0) sol += (long long)A[i]-Stek[Sh];
      while (Stek[Sh] <= A[i] && Sh>0) Sh--;
      Sh++;
      Stek[Sh] = A[i];
   }
   printf("%lld\n",sol);
   return 0;
}

