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

int main(){
  using ll= long long int;
  ll N,X;
  cin >> N >> X;

  ll ans= 0;
  ll prev,tmp;
  cin >> prev;
  ans+= max(0LL, prev-X);
  prev= min(prev, X);
  for(int i=1; i<N; i++){
    cin >> tmp;
    ans+= max(0LL, prev+ tmp- X);
    prev= min(tmp, X- prev);
  }

  cout << ans << endl;
}