#include "bits/stdc++.h" using namespace std; #define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i)) #define rep(i,j) FOR(i,0,j) #define each(x,y) for(auto &(x):(y)) #define mp make_pair #define mt make_tuple #define all(x) (x).begin(),(x).end() #define debug(x) cout<<#x<<": "<<(x)< pii; typedef vector vi; typedef vector vll; const ll INF = (ll)1e18; ll dp[200005][2]; int main(){ ios::sync_with_stdio(false); cin.tie(0); int N, P; cin >> N >> P; vll H(N); rep(i, N)cin >> H[i]; rep(i, N)rep(j, 2)dp[i][j] = INF; dp[0][0] = 0; rep(i, N - 1)rep(j, 2) { ll nex = dp[i][j]; if (!j&&H[i] < H[i + 1])nex += min((ll)P, H[i + 1] - H[i]); if (j&&H[i] > H[i + 1])nex += min((ll)P, H[i] - H[i + 1]); smin(dp[i + 1][j], nex); smin(dp[i + 1][!j], dp[i][j] + P); } cout << min(dp[N - 1][0], dp[N - 1][1]) << endl; }