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