#include using namespace std; const int MAXN = int(2e5); int N, P; int H[MAXN]; long long dpl[MAXN], dpr[MAXN]; signed main() { ios::sync_with_stdio(false); cin >> N >> P; for (int i = 0; i < N; ++i) { cin >> H[i]; } memset(dpl, 0x3f, sizeof(dpl)); memset(dpr, 0x3f, sizeof(dpr)); dpl[0] = dpr[0] = 0; for (int i = 1; i < N; ++i) { if (i == 1) { dpl[i] = P; } else { dpl[i] = min(dpl[i - 1] + min(P, max(0, H[i - 1] - H[i])), dpr[i - 1] + P); } dpr[i] = min(dpr[i - 1] + min(P, max(0, H[i] - H[i - 1])), dpl[i - 1] + P); } cout << min(dpl[N - 1], dpr[N - 1]) << endl; return 0; }