open Batteries
let n, lim = Scanf.scanf "%d %d" (fun x y -> x, y)
let rec solve acc = function
  | (x::y::ys) -> 
      let x' = min x lim in
      let y' = min y (lim - x') in
      let acc' = acc + max 0 (x+y-x'-y') in
      solve acc' (y'::ys)
  | _ -> acc
let a = List.init n (fun _ -> Scanf.scanf " %d" (fun x -> x))
let () = solve 0 a |> Printf.printf "%d\n"