#include <cstdio>
#include <iostream>
using namespace std;

int main(){
  int n; long long x; cin >> n >> x;
  long long prev = 0;
  long long ans = 0;
  for (int i = 0; i < n; i++) {
    long long k; cin >> k;
    if (prev + k > x) {
      ans += prev + k - x;
      k -= prev + k - x;
    }
    prev = k;
  }
  cout << ans << endl;
  return 0;
}
