//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,x;
    cin >> n >> x;
    vll a(n);
    REP(i,n) cin >> a[i];
    ll ans = 0;
    REP(i,n-1){
        ll sum = a[i] + a[i+1];
        ll t = min(a[i+1], max(0LL, sum-x));
        ans += t;
        a[i+1] -= t;
        sum -= t;
        t = min(a[i], max(0LL,sum-x));
        ans += t;
    }
    cout << ans << endl;
    return 0;
}
#include <bits/stdc++.h>

using namespace std;

int main(){

  int n, x;
  cin>>n>>x;
  
  long long int ans=0;
  long long int a;
  cin>>a;
  for(int i=0; i<n-1; i++){
    long long int b;
    long long int eat=0;
    cin>>b;
    
    eat=max(a+b-x, eat);
    ans+=eat;

    if(b<=eat) b=0;
    else b=b-eat;
    a=b;
  }

  cout<<ans<<endl;
}
