let n = Scanf.scanf " %d" (+) 0
let a_s = Array.init n @@ fun _ -> Scanf.scanf " %d" (+) 0
let i, ans = ref 1, ref 1
let _ = while !ans < n do i := a_s.(!i - 1); if !i = 2 then (Printf.printf "%d\n" !ans; exit 0); incr ans done;
  print_endline "-1"