#include <cstdio>
#include <iostream>

using namespace std;

int val[1000010];
long long sol;
int a,b,c;
int i;
int n,k;

int main()
{
    freopen("zetoni.in","r",stdin);
    freopen("zetoni.out","w",stdout);
    scanf("%d%d",&n,&k);
    for (a=1; a<=n; a++) scanf("%d",&val[a]), val[a]=k-val[a];
    i=0;
    for (a=1; a<=n; a++)
    {
        if (i>val[a]) i=val[a]; else sol+=1LL*val[a]-i, i=val[a];
    }
    printf("%I64d",sol);

}
