#include #define REP(x,y,z) for(int x=y;x<=z;x++) #define FORD(x,y,z) for(int x=y;x>=z;x--) #define MSET(x,y) memset(x,y,sizeof(x)) #define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++) #define F first #define S second #define MP make_pair #define PB push_back #define SZ size() #define M 200005 void RI(){} template void RI( int& head, T&... tail ) { scanf("%d",&head); RI(tail...); } using namespace std; typedef long long LL; int n; long long in[M],p; long long dp[M][2];//fr,bk LL calc() { dp[1][0] = 0; dp[1][1] = (1LL)<<60; REP(i,2,n) { dp[i][0] = dp[i-1][0] + min(max(in[i]-in[i-1],0LL), p); dp[i][1] = dp[i-1][1] + min(max(in[i-1]-in[i], 0LL), p); dp[i][1] = min(dp[i][1], dp[i-1][0] + p); dp[i][0] = min(dp[i][0], dp[i-1][1] + p); } return min(dp[n][0], dp[n][1]); } int main() { while(~scanf("%d %lld",&n,&p)) { REP(i,1,n) scanf("%lld",&in[i]); printf("%lld\n", calc()); } return 0; }