stdin.ReadLine()
|> int
|> (fun n ->
    [| 1..n |]
    |> Array.map (fun _ -> stdin.ReadLine() |> int)
    |> fun list -> 0::list
)
|> (fun list ->
    list
    |> Array.fold (
        fun (acc, i, found) _ ->
            match list.[i] with
            | 2 -> (acc + 1, 2, acc)
            | ai -> (acc + 1, ai, found)
    ) (1, 1, -1)
    |> fun (_, _, found) -> found
)
|> printfn "%d"
