#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int maxn=1e5+7;
ll a[maxn];
int main(){
    ll n,x;
    ll ans=0;
    cin>>n>>x;
    for(int i=0;i<n;i++) cin>>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]=max(x-a[i-1],(ll)0);
        }
    }
    cout<<ans<<endl;
    return 0;
}
