#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n,x,a[100010],i;
  long ans=0;
  cin >> n >> x;
  for (i=0;i<n;i++) cin >> a[i];
  for (i=0;i<n-1;i++){
    if (a[i]+a[i+1]<=x) continue;
    ans+=a[i+1]+a[i]-x;
    if (a[i]>=x){
      a[i+1]=0;
      a[i]=x;
    }else a[i+1]=x-a[i];
  }
  cout << ans << endl;
  return 0;
}