let () =
  let n,x = Scanf.scanf "%d %d " (fun a b -> a,b) in
  let a_lst = Array.to_list @@ Array.init n (fun _ -> Scanf.scanf "%d " (fun a -> a)) in

  let rec aux res prev = function
      [] -> res
    | hd :: tl -> 
      let sum = prev+hd in
      if sum<=x then aux res hd tl else
        let d = sum-x in
        aux (res+d) (hd-d) tl 
  in
  Printf.printf "%d\n" @@
  aux 0 0 a_lst
