let n = stdin.ReadLine() |> int
let a = stdin.ReadLine().Split(' ') |> Array.map int |> Array.toList
 
let rec solve c data =
    match List.skipWhile (fun x -> x <> c) data with
    | [] -> n - c + 1
    | xs -> solve (c + 1) xs
 
solve 1 a
|> fun x -> if x = n then -1 else x
|> printfn "%d"