#define _CRT_SECURE_NO_WARNINGS
#include <iterator>
#include <set>
#include <queue>
#include <iostream>
#include <sstream>
#include <stack>
#include <deque>
#include <map>
#include <cmath>
#include <memory.h>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <algorithm>
#include <utility>
#include <time.h>
using namespace std;
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define RFOR(i,b,a) for (int i = (b) - 1; i >= (a); i--)
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define PB push_back
#define MP make_pair
typedef long long Int;
typedef vector<int> VI;
typedef pair<int, int> PII;
const double PI = acos(-1.0);
const int INF = 1000 * 1000 * 1000;
const Int LINF = INF * (Int) INF;
const int MAX = 200007;
const int MOD = 1000000007;
int n, x;
int a[1000000];
long long ans = 0;
map<int, int> M;
int remove(map<int, int>::iterator it, int val) {
if (it->second <= val) {
val -= it->second;
M.erase(it);
return val;
}
it->second -= val;
return 0;
}
int main() {
scanf("%d%d", &n, &x);
FOR (i,0,n) scanf("%d", a+i);
int ost = 0;
FOR (ind,0,n) {
int d = a[ind] - (ind ? a[ind-1] : 0);
//cout << d << " -> "<<ans<<" "<<ost<<endl;
//for (auto it = M.begin(); it != M.end(); it ++)
// cout << it->first<<" "<<it->second<<endl;
if (d >= 0) {
int xf = d/x;
ans += xf;
if (xf) M[x-1] += xf;
d %= x;
if (ost + d >= x) {
ost = ost - x + d;
ans++;
M[d-1]++;
} else {
ost += d;
if (M.empty() || d <= 1 + M.begin()->first) {
ans += d;
} else {
ans += 1 + M.begin()->first;
remove(M.begin(), 1);
M[d-1]++;
}
}
} else {
d *= -1;
int num = d/x;
d %= x;
while (num) {
auto i = M.end(); i--;
num = remove(i, num);
}
if (ost < d) {
ost += x - d;
if (M.begin()->first + d >= x) {
ans += x - d;
auto i = M.end(); i--;
remove(i,1);
} else {
ans += M.begin()->first;
remove(M.begin(), 1);
if (!M.empty()) {
auto i = M.end(); i--;
if (i->first + d > x) {
remove(i, 1);
M[x-d]++;
}
}
}
} else {
ost -= d;
if (!M.empty()) {
auto i = M.end(); i--;
if (i->first + d > x) {
remove(i, 1);
M[x-d]++;
}
}
}
}
}
cout << ans;
}