fun main(args: Array<String>) {
    val A = IntArray(readLine()!!.toInt()) { readLine()!!.toInt() }

    var index = 1 - 1
    var count = 0
    while (count <= A.size) {
        count++
        val light = A[index]
        if (light == 2) {
            println(count)
            return
        }
        index = light - 1
    }
    println(-1)
}

