let _ =
  let nk = List.map int_of_string @@ Str.split (Str.regexp "[ \t]+") (read_line ()) in
  let hs = List.map int_of_string @@ Str.split (Str.regexp "[ \t]+") (read_line ()) in
  let rec f ph ls acc =
    match ls with
      [] -> acc
    | (h::t) -> if (ph + 1) <= h then f h t acc else f (ph + 1) t (acc + ph + 1 - h) in
  print_endline @@ string_of_int @@ f (List.hd hs) (List.tl hs) 0
