local n,x=io.read("n","n")
local a={}
for i=1,n do
    a[i]=io.read("n")
end

local counter=0
for i=1,n do
    local sum=a[i]+a[i+1]
    if sum>x then
        local diff=sum-x
        counter=counter+diff
        if diff<a[i+1] then
            a[i+1]=a[i+1]-diff
        else
            diff=diff-a[i+1]
            a[i+1]=0
            a[i]=a[i]-diff
        end
    end
end
print(counter)