import java.io.PrintWriter
val pw = PrintWriter(System.out)

fun main(args : Array<String>) {
    func()
    pw.flush()
}

fun func() {
    val n = nextInt()
    var aa = mutableListOf<Int>()
    val flags = Array(n){false}

    repeat(n) {
        aa.add(nextInt())
    }

    var nextIndex = 0
    var cnt = 0
    for (i in 0 until n) {
        cnt++
        if (aa[nextIndex] == 2) {
            println(cnt)
            return
        }
        if (flags[nextIndex]) {
            println(-1)
            return
        }
        flags[nextIndex] = true
        nextIndex = aa[nextIndex] - 1
    }

    println(-1)
}

fun next() = readLine()!!
fun nextInt() = next().toInt()

fun println(value : Any) {
    pw.println(value)
}