#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
  ll N, X;
  cin >> N >> X;
  ll a[N];
  for(int i = 0; i < N; i++) cin >> a[i];
  ll ans = 0;
  for(ll i = 0; i < N - 1; i++){
    if(a[i] + a[i + 1] <= X) continue;
    ll sub = a[i] + a[i + 1] - X;
    ans += sub;
    a[i + 1] = max<ll>(0, a[i + 1] - sub);
  }
  cout << ans << endl;
  return 0;
}