integer N,x
integer(16),allocatable,dimension(:)::A
integer(16) ans
read*,N,x
allocate(A(n))
read*,A
ans=0
if(A(1)>=x)then
  ans=A(1)-x
  A(1)=x
end if
do i=2,N
  if(A(i)+A(i-1)<=x)cycle
  ans=ans + (A(i)+A(i-1)-x)
  A(i)=x-A(i)
end do
print"(i0)",ans
end