#include using namespace std; using ll = long long; int main(){ ios::sync_with_stdio(false); cin.tie(0); int n, p; cin >> n >> p; vector a(n), b; b.reserve(n); for(int i = 0; i < n; i++){ cin >> a[i]; while(b.size() >= 2 && ((b.rbegin()[1] >= b.back() && b.back() >= a[i]) || (b.rbegin()[1] <= b.back() && b.back() <= a[i]))){ b.pop_back(); } b.emplace_back(a[i]); } b.insert(b.begin(), a[0]); b.push_back(a.back()); n = b.size(); vector dp(n, 1ll << 60); dp[0] = 0; for(int i = 0; i + 1 < n; i++){ dp[i + 1] = min(dp[i + 1], dp[i] + max(0, b[i + 1] - b[i])); dp[i + 1] = min(dp[i + 1], dp[i] + p); if(i + 2 < n) dp[i + 2] = min(dp[i + 2], dp[i] + p); } cout << dp.back() << '\n'; }