let n = Scanf.sscanf (read_line ()) "%d" @@ fun n -> n
let p = Array.init n @@ fun _ -> int_of_string (read_line ())

let () =
  let t = Array.make (n + 1) 0 in
  Printf.printf "%d\n" @@ Array.fold_left (fun m i -> 
    t.(i) <- t.(i - 1) + 1; min m (n - t.(i))
  ) n p