#include <cstdio>
#include <utility>
#include <queue>
using namespace std;
int i,N,L,t,tr[100002],s,u;
int main(){
	typedef pair<int,int>pii;
	priority_queue<pii> qu;
	
	scanf("%d%d",&N,&L);
	for(;i++<N;)scanf("%d",tr+i);

	for(i=0;i++<N;)
		if(tr[i]>tr[i-1]&tr[i]>tr[i+1]){
			qu.push(pii(tr[i]-L,i));
			tr[i]=L;
		}

	while(!qu.empty()){
		pii p=qu.top();
		qu.pop();
		
		t=p.first;
		tr[s=p.second]=0;
		
		u=tr[s-1];
		if(u&&u!=L&&u>tr[s-2]){
			qu.push(pii(t-L+u,s-1));
			tr[s-1]=L;
		}
		u = tr[s+1];
		if(u&&u!=L&&u>tr[s+2]){
			qu.push(pii(t-L+u,s+1));
			tr[s+1]=L;
		}
	}
	printf("%d\n",-t);
}