fun main(args: Array<String>) {
    abc065b()
}

fun abc065b() {
    val n = readLine()!!.toInt()
    val aList = (1..n).map { readLine()!!.toInt() - 1 }

    var curr = 0
    var cnt = 0
    for (i in aList.indices) {
        curr = aList[curr]
        cnt++
        if (curr == 1) break
    }

    val answer = if (curr == 1) cnt else -1

    println(answer)
}
