open Printf
open Scanf

let id x = x

let solve n =
  let g x = if x == n then -1 else x in
  let f (ct, i) x = if i = x then (ct, i + 1) else (ct + 1, i) in
  g @@ fst @@ Array.fold_left f (0, 1) @@ Array.init n @@ fun _ -> scanf "%d " id

let () =
  scanf "%d " solve |> printf "%d\n"
