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):

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



v = 0

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

    if (K >> i) & 1:

        v = to[v][i]



print((v + 1))
def main():

    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):

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



    v = 0

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

        if (K >> i) & 1:

            v = to[v][i]



    print((v + 1))





if __name__ == "__main__":

    main()
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):
        to[i][j + 1] = to[to[i][j]][j]
v = 0
for i in reversed(list(range(D))):
    if (K >> i) & 1:
        v = to[v][i]
print((v + 1))

def main():
    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):
            to[i][j + 1] = to[to[i][j]][j]
    v = 0
    for i in reversed(list(range(D))):
        if (K >> i) & 1:
            v = to[v][i]
    print((v + 1))


if __name__ == "__main__":
    main()

-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): -        to[i][j + 1] = to[to[i][j]][j] -v = 0 -for i in reversed(list(range(D))): -    if (K >> i) & 1: -        v = to[v][i] -print((v + 1)) +def main(): +    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): +            to[i][j + 1] = to[to[i][j]][j] +    v = 0 +    for i in reversed(list(range(D))): +        if (K >> i) & 1: +            v = to[v][i] +    print((v + 1)) + + +if __name__ == "__main__": +    main()