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

loop_checker = {}
before_loop_len = 0
loop_len = 0

count = 2
now = 0
while True:
    if A[now] in loop_checker.values():
        before_loop_len = loop_checker[A[now]]
        loop_len = count - before_loop_len - 1
        break
    else:
        loop_checker[count - 1] = A[now]
        now = A[now] - 1
        count += 1

if K <= before_loop_len:
    print(loop_checker[K])
else:
    checkK_prep = K - before_loop_len
    checkK = checkK_prep % loop_len
    print(loop_checker[before_loop_len + checkK])


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

flag = [False] * N
counted = [1]

nextT = A[0]
flag[0] = True
for x in range(N):
    if flag[nextT - 1] is False:
        counted.append(nextT)
        flag[nextT - 1] = True
        nextT = A[nextT - 1]
    else:
        break
before_loop_len = counted.index(nextT)
loop_len = x - before_loop_len + 1

if K <= before_loop_len:
    print(counted[K])
else:
    checkK_prep = K - before_loop_len
    checkK = checkK_prep % loop_len
    print(counted[before_loop_len + checkK])

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

loop_checker = [1]
before_loop_len = 0
loop_len = 0

now = 0
while True:
    if A[now] in loop_checker:
        before_loop_len = loop_checker.index(A[now])
        loop_slice = loop_checker[before_loop_len:]
        loop_len = len(loop_slice)
        break
    else:
        loop_checker.append(A[now])
        now = A[now] - 1
if K <= before_loop_len:
    print(loop_checker[K])
else:
    checkK_prep = (K - before_loop_len)
    checkK = checkK_prep % loop_len
    print(loop_slice[checkK])


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

flag = [False] * N
counted = [1]

nextT = A[0]
flag[0] = True
for x in range(N):
    if flag[nextT - 1] is False:
        counted.append(nextT)
        flag[nextT - 1] = True
        nextT = A[nextT - 1]
    else:
        break
before_loop_len = counted.index(nextT)
loop_len = x - before_loop_len + 1

if K <= before_loop_len:
    print(counted[K])
else:
    checkK_prep = K - before_loop_len
    checkK = checkK_prep % loop_len
    print(counted[before_loop_len + checkK])

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

loop_checker = [1]
before_loop_len = 0
loop_len = 0

now = 0
while True:
    if A[now] in loop_checker:
        index_val = loop_checker.index(A[now])
        loop_slice = loop_checker[index_val:]
        before_loop_len = loop_checker.index(A[now])
        loop_len = len(loop_slice)
        break
    else:
        loop_checker.append(A[now])
        now = A[now] - 1
if K <= before_loop_len:
    print(loop_checker[K])
else:
    checkK_prep = (K - before_loop_len)
    checkK = checkK_prep % loop_len
    print(loop_slice[checkK])


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

flag = [False] * N
counted = [1]

nextT = A[0]
flag[0] = True
for x in range(N):
    if flag[nextT - 1] is False:
        counted.append(nextT)
        flag[nextT - 1] = True
        nextT = A[nextT - 1]
    else:
        break
before_loop_len = counted.index(nextT)
loop_len = x - before_loop_len + 1

if K <= before_loop_len:
    print(counted[K])
else:
    checkK_prep = K - before_loop_len
    checkK = checkK_prep % loop_len
    print(counted[before_loop_len + checkK])