Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))

index = 1
route = [index]
node = [index]

for i in range(1, K + 1):
    index = A[index - 1]
    if index in node:
        pre = route.index(index)
        loop = len(route)
        route_idx = (K - pre) % (loop - pre) + pre
        print(route[route_idx])
        break
    else:
        route.append(index)
        node.append(index)
else:
    print(index)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

index = 1
route = [index]
node = {index}

for i in range(1, K + 1):
    index = A[index - 1]
    if index in node:
        pre = route.index(index)
        loop = len(route)
        route_idx = (K - pre) % (loop - pre) + pre
        print(route[route_idx])
        break
    else:
        route.append(index)
        node.add(index)
else:
    print(index)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

node = [0] * (N + 1)
index = 1
loop_flag = False

for i in range(1, K + 1):
    tmp = A[index - 1]
    if not node[tmp]:
        index = tmp
        node[index] += i
    else:
        pre = node[tmp]
        loop = index - node[tmp]
        if loop > 1:
            answer = node.index((K - pre) % loop + pre)
        else:
            answer = tmp
        loop_flag = True
        print(answer)
        break

if loop_flag == False:
    print(index)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

index = 1
route = [index]
node = {index}

for i in range(1, K + 1):
    index = A[index - 1]
    if index in node:
        pre = route.index(index)
        loop = len(route)
        route_idx = (K - pre) % (loop - pre) + pre
        print(route[route_idx])
        break
    else:
        route.append(index)
        node.add(index)
else:
    print(index)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

node = [0] * (N + 1)
index = 1
loop_flag = False

for i in range(1, K + 1):
    tmp = A[index - 1]
    if not node[tmp]:
        index = tmp
        node[index] += i
    else:
        pre = node[tmp]
        loop = index - node[tmp]
        if loop > 1:
            answer = node.index((K - pre) % loop + pre)
        else:
            answer = tmp
        loop_flag = True
        print(answer)
        break

if loop_flag:
    print(index)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

index = 1
route = [index]
node = {index}

for i in range(1, K + 1):
    index = A[index - 1]
    if index in node:
        pre = route.index(index)
        loop = len(route)
        route_idx = (K - pre) % (loop - pre) + pre
        print(route[route_idx])
        break
    else:
        route.append(index)
        node.add(index)
else:
    print(index)

Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))

node = [0] * (N + 1)
index = 1
loop_flag = False

for i in range(1, N + 1):
    tmp = A[index - 1]
    if not node[tmp]:
        index = tmp
        node[index] += i
    else:
        pre = node[tmp]
        loop = index - node[tmp]
        if loop > 1:
            answer = node.index((K - pre) % loop + pre)
        else:
            answer = tmp
        loop_flag = True
        print(answer)
        break

if loop_flag:
    print(index)

Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))

index = 1
route = [index]
node = {index}

for i in range(1, K + 1):
    index = A[index - 1]
    if index in node:
        pre = route.index(index)
        loop = len(route)
        route_idx = (K - pre) % (loop - pre) + pre
        print(route[route_idx])
        break
    else:
        route.append(index)
        node.add(index)
else:
    print(index)