fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val list = (0 until n).map { readLine()!!.toInt() - 1 }

    val path = mutableListOf<Int>()
    var position = 0
    repeat(n) {
        val next = list[position]
        path.add(next)
        if (next == 1) {
            println(path.size)
            return
        }
        position = next
    }

    println(-1)
}