#include <cstdio>
#include <utility>
#include <queue>
#include <vector>
using namespace std;

int main(){
	typedef pair<int,int> pii;
	
	priority_queue< pii, vector<pii>, greater<pii> > qu;
	int tr[100002];
	int i, N, L, t = 0;
	
	scanf("%d%d", &N, &L );
	for( i = 1; i <= N; i++ )	scanf("%d", tr + i );
	
	tr[0] = tr[N+1] = 0;
	for( i = 1; i <= N; i++ )
		if( tr[i] > tr[i-1] && tr[i] > tr[i+1] ){
			qu.push( pii( L - tr[i], i ) );
			tr[i] = L;
		}

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