fun main(args : Array<String>) {
    var N=readLine()!!.toInt()
    var A=(1..N).map{readLine()!!.toInt()}.map { it-1 }
    var visited=(1..N).map{false}.toMutableList()
    var current : Int=0
    var count=0
    while(true){
        if(current==1){
            println(count)
            break
        }
        if(visited[current]){
            println(-1)
            break
        }
        visited[current]=true
        count +=1
        current=A[current]
    }
   

}



fun ReadInts():MutableList<Int>{
    return readLine()!!.split(" ").map{it.toInt()}.toMutableList()
}

fun ReadLongs():MutableList<Long>{
    return readLine()!!.split(" ").map{it.toLong()}.toMutableList()
}
fun ReadDoubles():MutableList<Double>{
    return readLine()!!.split(" ").map{it.toDouble()}.toMutableList()
}