#include<stdio.h>
#include<algorithm>
using namespace std;
int main()
{
    int longth[2],n,lim,mem = -1,ud,sum,ans = 0;
    scanf("%d%d",&n,&lim);
    scanf("%d%d",&longth[0],&longth[1]);
    sum = 2 * lim - longth[0] - longth[1];
    if(longth[1] > longth[0])ud = 1;
    else ud = 0;
    mem = ud;
    longth[0] = longth[1];
    for(int i = 2; i < n + 1; i++)
    {
        if(i == n)
        {
            ans = max(ans,sum);
            break;
        }
        scanf("%d",&longth[1]);
        if(longth[1] > longth[0])ud = 1;
        else ud = 0;
        if(mem == ud)sum = sum + lim - longth[1];
        else
        {
            ans = max(ans,sum);
            sum = 2 * lim - longth[1] - longth[0];
            mem = ud;
        }
        longth[0] = longth[1];
    }
    printf("%d\n",ans);
}