#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
int n;
ll a[100005],x,Out;

int main(){
	cin>>n>>x;
	for(int i = 1; i <= n; i++) cin>>a[i];
	for(int i = 1; i <= n; i++){
		if(a[i] + a[i - 1] > x){
			Out += (1LL * a[i] + 1LL * a[i - 1] - 1LL*x);
			a[i] = x - a[i - 1];
		}
	}
	cout<<Out;
	return 0;
} 
