#include<bits/stdc++.h>
#define ll long long

using namespace std;

ll n,a[100010],x,ans;

int main()
{
	scanf("%lld%lld",&n,&x);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=1;i<=n;i++)
	{
		if(a[i]+a[i-1]>x)
		{
			ans+=(a[i]+a[i-1])-x;
			a[i]-=(a[i]+a[i-1])-x;
		}
		if(a[i]>x)
		{
			ans+=(a[i]-x);
			a[i]-=(a[i]-x);
		}
	}
	printf("%lld",ans);
	return 0;
}