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 i = 0, j = 0, r = 0L, ans = 0L; while (i < n-1 && j < n-1) { if (h[j+1] >= h[j]) { r += min(h[j+1]-h[j], p); ++j; } else { ans += j == n-1 ? min(r, p) : min(r, p*2); r = 0L; while (j < n-1 && h[j] > h[j+1]) ++j; i = j; } } if (i < j) ans += min(r, p); writeln(ans); }