program main
implicit none
integer(8) :: i, j, k
integer(8) :: n, x, res
integer(8) , allocatable :: a(:)

read(*,*) n, x
allocate( a(n) )
read(*,*) a
res = sum( max(a(1:n)-x,0) )
do i = 2, n
   if( min(x,a(i)) + min(x,a(i-1)) .ge. x ) then
      res = res + a(i) - (x-min(x,a(i-1)))
      a(i) = x - min(x,a(i-1))
   end if
end do
write(*,'(i0)') res


end program main
