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

  console.log('%s', ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));