#include using namespace std; #define repi(i,a,b) for(long long i = (long long)(a); i < (long long)(b); i++) using ll = long long; auto f = [](ll x, ll y, bool b) { return max(0ll, (b ? 1 : -1) * (y - x)); }; auto min3 = [](ll a, ll b, ll c) { return min(a, min(b, c)); }; int main(void) { ll n, p; cin >> n >> p; assert(n >= 2); assert(n <= 200000); assert(p >= 0); assert(p <= 1e9); ll a0, a1; cin >> a0 >> a1; assert(a0 >= 0); assert(a0 <= 1e9); assert(a1 >= 0); assert(a1 <= 1e9); ll w = p, r = f(a0, a1, true), l = f(a0, a1, false) + p; ll pw, pr, pl; repi(i, 1, n-1) { a0 = a1; cin >> a1; assert(a1 >= 0); assert(a1 <= 1e9); swap(w, pw); swap(l, pl); swap(r, pr); w = p + min3(pw, pr, pl); r = min(p, f(a0, a1, true )) + min(pw, pr); l = min(p, f(a0, a1, false)) + min(pw, pl); } cout << min3(w, r, l) << endl; return 0; }