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

int main(){
    int n,x;
    cin >> n >> x;
    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
    }
    ll cnt=0;
    if(a.at(0)>x){
        cnt+=a.at(0)-x;
        a.at(0)=x;
    }
    for(int i=1; i<n; i++){
        ll k=a.at(i)+a.at(i-1);
        if(k>x){
            cnt+=k-x;
            a.at(i) -= k-x;
        }
    }
    cout << cnt << endl;
}
#include<iostream>
#include<cstring>
#include<cstdio>
#include<vector>
#include<queue>
#include<cmath>
#include<algorithm>
using namespace std;

typedef long long ll;
const int mod=1e9+7;

int main(){
    int n,x,a;
    while(~scanf("%d%d%d",&n,&x,&a)){
        ll ans=0;
        if(a>x)
            ans+=a-x,a=x;
        while(--n){
            int b;
            scanf("%d",&b);
            if(a+b>x)
                ans+=a+b-x,a=x-a;
            else
                a=b;
        }
        printf("%lld\n",ans);
    }
    return 0;
}
