import java.util.Scanner

import scala.collection.mutable.ArrayBuffer
import scala.util.control.Breaks
import scala.math.abs

object Main extends App {

  val sc = new Scanner(System.in)
  val n, k = sc.nextInt()
  sc.nextLine()

  val a = sc.nextLine().split(" ").map(_.toInt)

  println(loop(0, 1))

  def loop(count: Int, index: Int): Long = {
    count match {
      case _ if count == k + 1 => a(index - 1)
      case _ => println(index); loop(count + 1, a(index - 1))
    }
  }

}
