fun main(){
    val nk = readLine()!!.split(" ").map { it.toLong() }
    val n = nk[0].toInt()
    val k = nk[1]
    val a = readLine()!!.split(" ").map { it.toInt() }
    var count:Long = 0//何回でループになるか数えてる
    val flagList = List(n){ 0 }.toMutableList()//index-1の町に何番目に行くかをまとめてる
    val countList = MutableList(n + 1){ 0 }//index+1番目にどの町にいくか
    flagList[0] = 1
    countList[0] = 1
    var amari = 0//ループに入る前に何回動いたか
    var mae = 0

    tailrec fun mytereport(y: Int) {
        count++
        if (flagList[a[y] - 1] != 0){
            mae = flagList[a[y] - 1]
            amari = mae - 1
            count -= amari
            return
        } else {
            flagList[a[y] - 1] = count.toInt() + 1
            countList[count.toInt()] = a[y]
            mytereport(a[y] - 1)
        }
    }
    mytereport(0)

    if (k > amari){
        val x = (k - amari) % count
        println(countList[amari + x.toInt()])
    } else {
        println(countList[k.toInt()])
    }

}


