import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val t = (1..n).map { sc.nextInt() - 1 }
    val used = mutableSetOf(0)
    var cur = 0
    while (true) {
        cur = t[cur]
        if (used.contains(cur) || cur == 1) {
            break
        }
        used.add(cur)
    }
    println(if (cur == 1) used.size else -1)
}