let ans, x, a_s = Scanf.(scanf "%d %d" @@ fun n x -> ref 0, x, Array.init n @@ fun _ -> scanf " %d" (+) 0)
let _ = Array.iteri (fun i a -> if i > 0 then let m = max 0 @@ a_s.(i - 1) + a - x in a_s.(i) <- max 0 @@ a - m; ans := !ans + m) a_s; Printf.printf "%d\n" !ans