open System
let N = stdin.ReadLine() |> int
let (A : int[]) = Array.zeroCreate N
for i in 0..(N-1) do A.[i] <- (stdin.ReadLine() |> int) - 1

let rec f n tot =
  match (n, tot) with
    | (_, tot) when tot > N -> -1
    | (n, _) when A.[n] = 1 -> tot + 1
    | _ -> f A.[n] (tot + 1)

f 0 0 |> printfn "%d"
