#include using namespace std; using ll = long long; ll h[200005], a[200005]; int main() { cin.tie(0); ios::sync_with_stdio(false); int n; ll p; cin >> n >> p; for (int i = 0; i < n; i++) { cin >> h[i]; } for (int i = n - 2; i >= 0; i--) { a[i] = a[i + 1] + min(max(h[i] - h[i + 1], 0LL), p); } ll cur = 0, ans = 1000000000000000LL; for (int i = 0; i < n - 1; i++) { ans = min(ans, cur + a[i]); cur += max(h[i + 1] - h[i], 0LL); } ans = min(ans, cur); cout << ans << endl; return 0; }