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

T=str(bin(K))

S=len(T)-2

A = list(map(int,input().split()))

lst=[[0 for e in range(N+1)] for f in range(S)]

for i in range(1,N+1):

 lst[0][i]=A[i-1]

for j in range(1,S):

 for i in range(1,N+1):

  lst[j][i]=lst[j-1][lst[j-1][i]]

ans=[[e for e in range(N+1)] for f in range(S+1)]

for k in range(S):

 if int(T[k+2])==1:

  for l in range(1,N+1):

   ans[k+1][l]=lst[S-1-k][ans[k][l]]

 else:

  for l in range(1,N+1):

   ans[k+1][l]=ans[k][l]

print((ans[S][1]))

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

T=str(bin(K))

S=len(T)-2

A = list(map(int,input().split()))

lst=[[0 for e in range(N+1)] for f in range(S)]

for i in range(1,N+1):

 lst[0][i]=A[i-1]

for j in range(1,S):

 for i in range(1,N+1):

  lst[j][i]=lst[j-1][lst[j-1][i]]

ans=1

for k in range(S):

 if int(T[k+2])==1:

  ans=lst[S-1-k][ans]

print(ans)
N, K = list(map(int, input().split()))
T = str(bin(K))
S = len(T) - 2
A = list(map(int, input().split()))
lst = [[0 for e in range(N + 1)] for f in range(S)]
for i in range(1, N + 1):
    lst[0][i] = A[i - 1]
for j in range(1, S):
    for i in range(1, N + 1):
        lst[j][i] = lst[j - 1][lst[j - 1][i]]
ans = [[e for e in range(N + 1)] for f in range(S + 1)]
for k in range(S):
    if int(T[k + 2]) == 1:
        for l in range(1, N + 1):
            ans[k + 1][l] = lst[S - 1 - k][ans[k][l]]
    else:
        for l in range(1, N + 1):
            ans[k + 1][l] = ans[k][l]
print((ans[S][1]))

N, K = list(map(int, input().split()))
T = str(bin(K))
S = len(T) - 2
A = list(map(int, input().split()))
lst = [[0 for e in range(N + 1)] for f in range(S)]
for i in range(1, N + 1):
    lst[0][i] = A[i - 1]
for j in range(1, S):
    for i in range(1, N + 1):
        lst[j][i] = lst[j - 1][lst[j - 1][i]]
ans = 1
for k in range(S):
    if int(T[k + 2]) == 1:
        ans = lst[S - 1 - k][ans]
print(ans)

-ans = [[e for e in range(N + 1)] for f in range(S + 1)] +ans = 1 -        for l in range(1, N + 1): -            ans[k + 1][l] = lst[S - 1 - k][ans[k][l]] -    else: -        for l in range(1, N + 1): -            ans[k + 1][l] = ans[k][l] -print((ans[S][1])) +        ans = lst[S - 1 - k][ans] +print(ans)