#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;

int main(){
	int n,l;
	cin>>n>>l;
	int icic[114514];
	icic[0]=0;
	icic[1]=0;
	for(int i=0;i<n;i++)cin>>icic[i+2];
	icic[n+2]=0;
	icic[n+3]=0;
	int t=0;
	
	priority_queue<P>Q;
	for(int i=1;i<=n+2;i++){
		if(icic[i]>icic[i-1]&&icic[i]>icic[i+1]){
			Q.push(P(icic[i],i));
			}
		}
		
		while(Q.size()){
			P p=Q.top();
			Q.pop();
			
			if(p.first==0)continue;
			t+=(l-p.first-t);
				
			icic[p.second]=0;	
			if(icic[p.second-2]<icic[p.second-1])Q.push(P(icic[p.second-1]-t,p.second-1));
			if(icic[p.second+2]<icic[p.second+1])Q.push(P(icic[p.second+1]-t,p.second+1));	
			}
			cout<<t<<endl;
			return 0;
	}