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=0L;
  long result=0;
  foreach(a; as){
    if(a+c>x){
      result+=a+c-x;
      c=-c+x;
    }else{
      c=a;
    }
  }
  writeln(result);
}
