#include<iostream>
#include<map>
#include<queue>
#define mp(a,b) make_pair(a,b)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int n,m;
  cin >> n >> m;
  int t[100005]={};
  priority_queue<P,vector<P> > q;
  int i,j,k;
  for(i=0;i<n;i++){
    cin >> k;
    q.push(mp(k,i));
  }
  int o=0,time;
  while(!q.empty()){
    P f=q.top();q.pop();
    if(f.second==0){
      time=t[1];
    }else if(f.second==n-1){
      time=t[n-2];
    }else{
      time=max(t[f.second-1],t[f.second+1]);
    }
    t[f.second]=time+m-f.first;
    o=max(o,t[f.second]);
  }
  cout << o << endl;
  return 0;
}