let n = read_int ()
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let rec f m i = if i >= n then -1 else if a_s.(i) = m then i else f m (i + 1)
let rec g i j = let j = f i j in if j = -1 then i - 1 else g (i + 1) (j + 1)
let k = g 1 0
let _ = Printf.printf "%d\n" @@ if k = 0 then -1 else n - k