#include <iostream>
using namespace std;
int main(){
  long long int ans = 0;
  int n, x;
  cin >> n >> x;
  int a[n];
  for(int i = 0; i<n; ++i) cin >> a[i];
  if(a[0]>x){
    ans += a[0] - x;
    a[0] -= ans;
  }
  for(int i = 0; i<n-1; ++i){
    if(a[i]+a[i+1]>x){
      ans += a[i]+a[i+1]-x;
      a[i+1] -= a[i]+a[i+1]-x;
    }
  }
  cout << ans << endl;
}
