let n, x = Scanf.scanf "%d %d\n" (fun a b -> a, b)
let a = Str.split (Str.regexp " ") @@ read_line () 
      |> List.map int_of_string

let rec cutting l =
  let rec func cnt res = function
      [] -> (cnt, List.rev res)
    | hd :: rest ->
      let n = max 0 (hd-x) in
      func (cnt + n) ((min x hd)::res) rest
  in func 0 [] l

let checking (pre_ans, l) =
  let rec func cnt = function
      [] | [_] -> cnt
    | o::t::rest ->
        let n = max 0 (o+t - x) in
        func (cnt+n) ((max 0 (t-n)) :: rest)
  in
  pre_ans + func 0 l
      

let () =
  cutting a
  |> checking
  |> (print_endline $ string_of_int)
