#include #include #include #include #include using namespace std; typedef long long ll; typedef pair P; ll N,L,X[100010] = {},Y[100010] = {}; vector

v,u; int main(){ cin >> N >> L; set s; assert(N<=100000 && L<=1000000000); for(int i=1;i<=N;i++){ cin >> X[i]; assert(X[i-1]> Y[i]; assert(Y[i-1]cnt){ mi = cnt; q = i; } } cerr << ma << " " << mi << endl; if(mi>=0){ cout << (ma-1)*L + v[p+1].first << endl; return 0; } bool sushi = false; for(int i=0;i<=q;i++){ if(v[i].second==1){ if(sushi) u.push_back(P(v[i].first+L,1)); else sushi = true; }else{ if(sushi && i==q) sushi = false; else u.push_back(P(v[i].first+L,-1)); } } for(int i=q+1;i<2*N;i++) u.push_back(v[i]); sort(u.begin(),u.end()); ma = 0; p = 0; cnt = 0; assert(u.size()==2*N-2); for(int i=0;i<(int) u.size();i++){ cnt += u[i].second; if(ma<=cnt){ ma = cnt; p = i; } } cerr << ma << " " << endl; cout << (ma-1)*L + u[p+1].first << endl; return 0; }