fun main() {
    val (n, k) = readLine()?.split(" ")?.map(String::toLong) ?: return
    val a = readLine()?.split(" ")?.map(String::toInt) ?: return
    val arrival = Array(n.toInt() + 1) { false }
    val loopRoutes = mutableListOf<Int>()

    var c = a[0]
    arrival[1] = true
    loopRoutes.add(1)
    loopRoutes.add(c)
    while (true) {
        val t = a[c - 1]
        if (arrival[t]) {
            val r = k - loopRoutes.size
            if (r < 0) {
                println(loopRoutes[(k).toInt()].toString())
                return
            } else if (r == 0L) {
                println(t.toString())
                return
            }
            val loop = loopRoutes.drop(loopRoutes.indexOf(t))
            if (loop.size == 1) {
                println(loop.first().toString())
                return
            }
            val p = r % loop.size
            println((loop[p.toInt()]).toString())
            return
        } else {
            arrival[t] = true
            loopRoutes.add(t)
            c = t
        }
    }
}

