Scanf.scanf "%d %d" (fun n k ->
    let a = Array.init n (fun _ -> Scanf.scanf " %d" (fun a -> a - 1)) in
    let tel = Array.make n (-1) in
    let ord = Array.make n (-1) in
    tel.(0) <- 0;
    ord.(0) <- 0;

    let rec loop step cur =
        let step = step + 1 in
        let cur = a.(cur) in
        if step = k then cur + 1 else
        if tel.(cur) = -1 then (
            tel.(cur) <- step;
            ord.(step) <- cur;
            loop step cur
        ) else (
            let len = step - tel.(cur) in
            let rest = (k - step) mod len in
            ord.(tel.(cur) + rest) + 1
        )
    in
    loop 0 0 |> Printf.printf "%d\n"
)