fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val v = (1..n).map{readLine()!!.toInt()}
    println(calcAns(n, v))
}

fun calcAns(n: Int, v: List<Int>): Int {
    var now = 0
    for (i in 0..n - 1) {
        if (now == 1) {return i}
        now = v[now] - 1
    }
    return -1
}