Option Infer On
Imports System.Console

Module Program
    Sub Main()
        Dim N As Integer = CInt(ReadLine())
        Dim a As Integer() = New Integer(N - 1) {}

        For i = 0 To N - 1
            a(i) = CInt(ReadLine())
        Next

        Dim j = 1
        For i = 1 To N
            j = a(j - 1)
            If j = 2 Then
                WriteLine(i)
                Exit Sub
            End If
        Next

        WriteLine(-1)
    End Sub

End Module
