let _ =
  Scanf.scanf "%d" @@ fun n ->
  let p = Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) in
  let c = Array.make (n+1) 0 in
  Array.fold_left (fun s x ->
    c.(x) <- c.(x-1) + 1;
    min s (n - c.(x))
  ) n p
  |> Printf.printf "%d\n"