#include<stdio.h>
int main(void){
  char *s="python3 -c\""
"n,x,*a=map(int,open(0).read().split())\n"
"a=[0]+a\n"
"c=0\n"
"for i in range(n):\n"
"  c+=max(0,a[i+1]+a[i]-x)\n"
"  a[i+1]=min(a[i+1],x-a[i])\n"
"print(c)\n"
"\"";
  system(s);
  return 0;
}            