let ans, a_s = ref 0, Array.init (read_int ()) @@ fun _ -> Scanf.scanf " %d" (+) 0
let f (p, c) a = a, if a <> p then (ans := !ans + if p > c then c else c - p; 1) else c + 1
let _ = Array.(sort (-) a_s; f (fold_left f (a_s.(0), 0) a_s) 0) |> ignore; Printf.printf "%d\n" !ans