let n = stdin.ReadLine() |> int

let a =
  [| for _ in 0 .. n - 1 -> stdin.ReadLine() |> (fun x -> int x - 1) |]

let ans =
  [1 .. n]
  |> List.scan (fun acc _ -> a.[acc]) 0
  |> List.tryFindIndex (fun i -> i = 1)
  |> (fun x ->
        match x with
        | Some i -> i
        | None -> -1 )

ans |> stdout.WriteLine