import std.stdio, std.string, std.algorithm, std.conv, std.array;

void main(){
  auto nx=readln.split.map!(to!long).array;
  auto n=nx[0], x=nx[1];
  auto as=readln.split.map!(to!long).array;
  auto c=as[0];
  long result=0;
  foreach(a; as[1..$]){
    if(a+c>x){
      result+=a+c-x;
      c=-c+x;
    }else{
      c=a;
    }
  }
  writeln(result);
}
