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

D = K.bit_length()

to = [[0] * D for _ in range(N)]



for i, a in enumerate(map(int, input().split())):

    to[i][0] = a - 1



for j in range(D - 1):

    for i in range(N):

        h = to[i][j]

        to[i][j+1] = to[h][j]



v = 0

for i in reversed(list(range(D))):

    x = 1 << i

    if x <= K:

        v = to[v][i]

        K -= x



print((v + 1))
N, K = list(map(int, input().split()))

D = K.bit_length()

to = [[0] * D for _ in range(N)]



for i, a in enumerate(map(int, input().split())):

    to[i][0] = a - 1



for j in range(D - 1):

    for i in range(N):

        h = to[i][j]

        to[i][j+1] = to[h][j]



v = 0

for i in reversed(list(range(D))):

    if (K >> i) & 1:

        v = to[v][i]



print((v + 1))
N, K = list(map(int, input().split()))
D = K.bit_length()
to = [[0] * D for _ in range(N)]
for i, a in enumerate(map(int, input().split())):
    to[i][0] = a - 1
for j in range(D - 1):
    for i in range(N):
        h = to[i][j]
        to[i][j + 1] = to[h][j]
v = 0
for i in reversed(list(range(D))):
    x = 1 << i
    if x <= K:
        v = to[v][i]
        K -= x
print((v + 1))

N, K = list(map(int, input().split()))
D = K.bit_length()
to = [[0] * D for _ in range(N)]
for i, a in enumerate(map(int, input().split())):
    to[i][0] = a - 1
for j in range(D - 1):
    for i in range(N):
        h = to[i][j]
        to[i][j + 1] = to[h][j]
v = 0
for i in reversed(list(range(D))):
    if (K >> i) & 1:
        v = to[v][i]
print((v + 1))

-    x = 1 << i -    if x <= K: +    if (K >> i) & 1: -        K -= x