import sys

readline = sys.stdin.readline

N,K = list(map(int,readline().split()))

A = [0] + list(map(int,readline().split()))

c = 1

while K:

  if K & 1:

    c = A[c]

  A = [A[A[i]] for i in range(len(A))]

  K >>= 1

print(c)
N,K=list(map(int,input().split()))

A=[0]+list(map(int,input().split()))

c=1

while K:

  if K&1:

    c=A[c]

  A=[A[A[i]] for i in range(len(A))]

  K>>=1

print(c)
import sys

readline = sys.stdin.readline
N, K = list(map(int, readline().split()))
A = [0] + list(map(int, readline().split()))
c = 1
while K:
    if K & 1:
        c = A[c]
    A = [A[A[i]] for i in range(len(A))]
    K >>= 1
print(c)

N, K = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))
c = 1
while K:
    if K & 1:
        c = A[c]
    A = [A[A[i]] for i in range(len(A))]
    K >>= 1
print(c)

-import sys - -readline = sys.stdin.readline -N, K = list(map(int, readline().split())) -A = [0] + list(map(int, readline().split())) +N, K = list(map(int, input().split())) +A = [0] + list(map(int, input().split()))