fun main(args: Array<String>) {
    val N = readLine()!!.toInt()
    val a = (1..N).map { readLine()!!.toInt() }
    var b = 1; var t = 0
    while (t <= N && b != 2) {
        b = a[b - 1]
        t++
    }
    println(if (t > N) -1 else t)
}