#include <iostream>
#include <fstream>
using namespace std;
long int a[1000000],n,k;
int s=0;
void seci(int i, int j)
{   int mih=0;
    for (int k=0;k<n;k++)
    {if(a[k]>mih) mih=a[k];}
    s+=mih;
    for (int k=i;k<j;k++)
    {a[i]=0;}
}
bool prazna()
{
for (int i=0;i<n;i++) if(a[i]!=0) return true;
return false;
}

int main()
{   ifstream fin("zetoni.in");
    ofstream fout("zetoni.out");
    fin>>n>>k;
    long int mih=3000000000;
    for (int i=0;i<n;i++)
    {fin>>a[i];a[i]=k-a[i];}
    bool t=true;
    long int t1=0,t2=n-1;
    for (int i=0;i<n;i++)
    {if(a[i]<mih) mih=a[i];}
    s+=mih;
    if(mih>0)
    for (int i=0;i<n;i++)
    {a[i]=a[i]-mih;}
    while(prazna())
    {t=true;
    for(int i=0;i<n;i++)
    {
    if (a[i]==0){if(t==true) {t1=i; t=false;}
                    else {while(a[i]==0) i++; t=true; seci(t1,i);}
                }
    }
    }
    fin.close();
    fout.close();
    fout<<s;
    return 0;

}
