#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9;

int main() {
  int  n, x;
  cin>>n>>x;
  int a[n];
  for (int i=0; i<n; i++) cin>>a[i];

  long long cnt = 0;
  if (a[0] > x) {
    cnt += a[0] - x;
    a[0] = x;
  }
  for (int i=1; i<n; i++) {
    if (a[i-1] + a[i] > x) {
      cnt += a[i] + a[i-1] - x;
      a[i] = x - a[i-1];
    }
  }
  cout<<cnt<<endl;
}