(* O(n) *)
let n = Scanf.scanf " %d" @@ (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" @@ fun a -> a - 1
let rec loop acc i =
  if acc > n then (print_endline "-1"; exit 0)
  else if i = 1 then (Printf.printf "%d\n" acc; exit 0)
  else loop (acc + 1) a_s.(i)
let _ = loop 0 0