#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
int n, x;
cin >> n >> x;
vector<int> a(n);
for (int i = 0; i < n; i++) {
cin >> a[i];
}
int s = 0;
for (int i = 0; i < n; i++) {
int t = 0;
if (a[i] > x) {
t = a[i] - x;
a[i] = x;
s += t;
}
}
for (int i = 0; i < n - 1; i++) {
int t = 0;
if (a[i] + a[i + 1] > x) {
t = a[i] + a[i + 1] - x;
a[i + 1] -= t;
s += t;
}
t = 0;
}
cout << s << endl;
return 0;
}