let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" pred
let j = ref 0
let _ = for i = 1 to n do j := a_s.(!j); if !j = 1 then (Printf.printf "%d\n" i; exit 0) done; print_endline "-1"