#include<iostream>
#include<cmath>
using namespace std;
const int maxn = 1e5 + 5;
long long n, x, cnt;
long long a[maxn];
int main(){
	cin >> n >> x;
	for(int i = 1;i <= n;i++){
		cin >> a[i];
		if(a[i] + a[i - 1] <= x){
			continue;
		}
		cnt += abs(a[i] + a[i - 1] - x);
		a[i] = x - a[i - 1];
	}
	cout << cnt << endl;
	return 0;
}