#include <bits/stdc++.h>
#define INF 1e+10
#define f first
#define s second
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;

int a[200000],n,m;
ll dist[200000];

int main(){
  cin>>n>>m;
  for(int i=1;i<=n;i++) cin>>a[i];
  for(int i=0;i<=n+1;i++) dist[i]=INF;
  priority_queue < P, vector< P >, greater < P > > Q;
  for(int i=1;i<=n;i++) if(a[i]>a[i-1] && a[i]>a[i+1]) Q.push(P(0,i));
  while(!Q.empty()){
    ll cost = Q.top().f,p=Q.top().second;
    Q.pop();
    cost += m-a[p];
    dist[p]=cost;
    if(p-1>0 && a[p]>a[p-1]) Q.push(P(cost,p-1));
    if(p+1<=n && a[p]>a[p+1]) Q.push(P(cost,p+1));
  }
  ll ans=-1;
  for(int i=1;i<=n;i++) ans = max(ans,dist[i]);
  cout<<ans<<endl;

  return 0;
}