program prob6
    implicit none
    integer(8) :: N, x
    integer(8), allocatable :: A(:)
    integer(8) :: i, ans
    read(*,*) N, x
    allocate(A(N))
    read(*,*) A

    ans = max(A(1) - x, 0)
    A(1) = min(A(1), x)
    do i = 2, N
        if(A(i) + A(i-1) > x) then
            ans = ans + A(i) + A(i-1) - x
            A(i) = x - A(i-1)
        end if
    end do
    write(*,*) ans




    deallocate(A)

    stop
contains
end program prob6