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



}