#include<bits/stdc++.h>
#define rep(i,j,k) for(int i=(j);i<(k);i++)
#define mp make_pair
#define sz(a) (int)(a).size()
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<double,double> pdd;
typedef long double ld;
//----head----
int data[100005];
int main()
{
	int n,x;
	scanf("%d%d",&n,&x);
	rep(i,1,n+1)scanf("%d",&data[i]);
	int ans=0;
	rep(i,1,n+1)if(data[i]>x)
	{
		ans+=data[i]-x;
		data[i]=x;
	}
	rep(i,2,n+1)if(data[i]+data[i-1]>x)
	{
		int a=x-data[i-1];
		ans+=data[i]-a;
		data[i]=a;
	}
	printf("%d\n",ans);
	return 0;
}
