program abc048c
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int64):: n,x,ans=0,i
    integer(int64), allocatable:: a(:)

    read*, n,x
    allocate(a(n))
    read*, a(:)

    if (a(1) > x) then
        ans=ans+a(1)-x
        a(1) = x
    end if

    do i=2,n
        if (a(i) > x - a(i-1)) then
            ans=ans+sum(a(i-1:i))-x
            a(i) = x - a(i-1)
        end if
    end do
    print'(i0)', ans
end program abc048c