local n, x = io.read("*n", "*n", "*l")
local str = io.read()
local a = {}
for v in str:gmatch("%d+") do
  table.insert(a, tonumber(v))
end
local cnt = 0
for i = 1, n - 1 do
  local rem = a[i] + a[i + 1] - x
  if 0 < rem then
    cnt = cnt + rem
    if rem <= a[i + 1] then
      a[i + 1] = a[i + 1] - rem
    else
      a[i + 1] = 0
      a[i] = a[i] - (rem - a[i + 1])
    end
  end
end
print(cnt)
