function Main(input) {
  input = input.split("\n");
  var n = parseInt(input[0].split(" ")[0]);
  var x = parseInt(input[0].split(" ")[1]);
  tmp = input[1].split(" ");
  a = new Array(n).fill(0);
  for(i=0;i<n;i++){
    a[i]=parseInt(tmp[i]);
  }
  var ans=0;
  for(i=0;i<n;i++){
    if(i==0){
      if(a[i]>x){
        ans+=a[i]-x;
        a[i]=x;
      }
    }else{
      if(a[i]+a[i-1]>x){
        ans+=a[i-1]+a[i]-x;
        a[i]=x-a[i-1];
      }
    }
  }

  console.log('%s', ans);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));
