let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let tele = Array.make_matrix n 62 0 in
  for i = 0 to n - 1 do
    Scanf.scanf "%d " @@ fun a ->
      tele.(i).(0) <- a - 1
  done;
  for j = 0 to 60 do
    for i = 0 to n - 1 do
      tele.(i).(j + 1) <- tele.(tele.(i).(j)).(j)
    done
  done;
  Printf.printf "%d\n" @@
  succ @@
  List.fold_left (fun c i ->
    if k land (1 lsl i) = 0
    then c
    else tele.(c).(i)) 0 @@
  List.init 62 Fun.id

