import std.algorithm, std.conv, std.range, std.stdio, std.string; void main() { auto rd = readln.split.to!(int[]), n = rd[0], p = rd[1].to!long; auto h = readln.split.to!(long[]); auto calc(int i, int j) { auto r = 0; r += min(h[j]-h[i], p); if (j-i > 1 && j < n-1) { r += min(h[j]-h[i], p); } return r; } auto i = 0, j = 0, ans = 0L; while (i < n-1 && j < n-1) { if (h[j+1] >= h[j]) { ++j; } else { ans += calc(i, j); while (j < n-1 && h[j] > h[j+1]) ++j; i = j; } } if (i < j) ans += calc(i, j); writeln(ans); }