#include using namespace std; using ll = long long; int main() { ios::sync_with_stdio(false); cin.tie(nullptr); ll N, K; cin >> N >> K; vector H(N); for(auto &i : H) { cin >> i; } H.emplace_back(0); vector v; ll l = H[0]; for(ll i = 0; i < N; i++) { if(H[i] > H[i + 1]) { v.emplace_back(H[i] - l); l = H[i + 1]; } } ll ans = 0; for(auto &i : v) { ans += min(i, K); } cout << ans << "\n"; }