#include <bits/stdc++.h>
#define sz(x) ((int)(x).size())
#define rep(i,a,b) for (int i=(a); i<(b); i++)
using namespace std;
typedef long long ll;
const int MAX_N = 7 + 100000;
///----------------------------------------------
int dig[MAX_N];
int main() {

    //freopen ( "xx.in" ,  "r" , stdin );

    ///read
    int n,m; cin>>n>>m;
    rep(i,0,n) scanf("%d",&dig[i]);

    ///work
    ll ans=0;
    rep(i,1,n) if (dig[i]+dig[i-1]>m) {
        ans+=dig[i]+dig[i-1]-m;
        dig[i]=m-dig[i-1];
    }
    cout << ans;

}
