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

int main () {
  int n, x; cin >> n >> x;
  
  int64_t ans =0;
  int a[100005];
  for (int i=0; i<n; i++)	{
    cin >> a[i];
  }
  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] = max(0, x-a[i]);
    }
  }
  cout << ans  << endl;
}