#include<bits/stdc++.h>
using namespace std;
int n;
const int maxn = 1e5 + 10;
long long a[maxn];
int x;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
cin >> n >> x;
for(int i = 0; i < n; i++)
cin >> a[i];
int sum = 0;
for(int i = 0; i < n - 1; i++)
{
if(a[i] + a[i + 1] > x)
{
sum += a[i] + a[i + 1] - x;
a[i + 1] -= a[i] + a[i + 1] - x;
}
}
cout << sum;
return 0;
}