program main
  implicit none
  integer :: n, x, i
  integer, allocatable :: a(:)
  read(*, *) n, x
  allocate(a(n))
  read(*, *) (a(i), i = 1, n)

  write(*, "(i0)") processes(n, x, a)

  deallocate(a)
  contains

  function processes(n, x, a)
    implicit none
    integer, intent(in) :: n, x
    integer, intent(inout) :: a(:)
    integer :: i, processes, eat
    processes = 0
    do i = 2, n
      eat = max(0, a(i) + a(i - 1) - x)
      processes = processes + eat
      a(i) = max(0, a(i) - eat)
    end do
  end function processes

end
