#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> PA;
int main(){
  int n,l;
  int a[100002];
  priority_queue<PA,vector<PA>,greater<PA> > pq;
  cin >> n >> l;
  for(int i=1;i<=n;i++) cin >> a[i];
  for(int i=1;i<=n;i++){
    if(a[i] > a[i-1] && a[i] > a[i+1]) pq.push(PA(l-a[i],i));
  }
  int keika = 0,ans = 0;
  PA p;
  while(!pq.empty()){
    p = pq.top();
    pq.pop();
    ans = max(ans,p.first);
    a[p.second] = 0;
    if(a[p.second-1] > a[p.second-2]){
      pq.push(PA(l-a[p.second-1]+p.first,p.second-1));
    }
    if(a[p.second+1] > a[p.second+2]){
      pq.push(PA(l-a[p.second+1]+p.first,p.second+1));
    }
  }
  cout << ans << endl;
  return (0);
}