import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val list = sc.asSequence().take(n).map(String::toInt).toList()
    var p = 1
    var r = 0
    (0..n).forEach {
        p = list[p - 1]
        r++
        if (p == 2) {
            println(r)
            return
        }
    }
    println(-1)
}
