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

    ans = 0
    do i = 2, N
        tmp = a(i-1) + a(i)
        if(tmp > x) then
            if(a(i) < x) then
                a(i) = 0
            else
                a(i) = a(i) - (tmp - x)
            end if
            ans = ans + tmp - x
        end if
    end do

    write(*,*) ans

    stop
end program