Buggy python submission (verdict: Runtime Error):
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = [0 for _ in range(N)]

now = 0
l[now] = 1
count = 0
loop = []

while count < K:
    count += 1
    now = A[now]-1
    loop.append(now)
    if l[now] == 1:
        loop = loop[loop.index(now):-1]
        break
    else:
        l[now] = 1

if count == K:
    print(now + 1)
else:
    ans = loop[K % count]
    print(ans + 1)


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = [0 for _ in range(N)]

now = 0
l[now] = 1
count = 0
loop = [0]

while count < K:
    count += 1
    now = A[now]-1
    loop.append(now)
    if l[now] == 1:
        loop = loop[loop.index(now):-1]
        break
    else:
        l[now] = 1

if count == K:
    print(now + 1)
else:
    ans = loop[(K-count) % len(loop)]
    print(ans + 1)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = [0 for _ in range(N)]

now = 0
l[now] = 1
count = 0

while count < K:
    count += 1
    now = A[now]-1
    if l[now] == 0:
        l[now] = 1
    else:
        break

if count == K:
    print(now + 1)
else:
    for i in range(K - count):
        now = A[now] - 1
    print(now + 1)


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = [0 for _ in range(N)]

now = 0
l[now] = 1
count = 0
loop = [0]

while count < K:
    count += 1
    now = A[now]-1
    loop.append(now)
    if l[now] == 1:
        loop = loop[loop.index(now):-1]
        break
    else:
        l[now] = 1

if count == K:
    print(now + 1)
else:
    ans = loop[(K-count) % len(loop)]
    print(ans + 1)

Buggy python submission (verdict: Time Limit Exceeded):
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = [0 for _ in range(N)]

now = 0
l[now] = 1
count = 0

while count < K:
    count += 1
    now = A[now]-1
    if l[now] == 0:
        l[now] = 1
    else:
        break

if count == K:
    print(now + 1)
else:
    for i in range(K - count):
        now = A[now] - 1
    print(now + 1)


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = [0 for _ in range(N)]

now = 0
l[now] = 1
count = 0
loop = [0]

while count < K:
    count += 1
    now = A[now]-1
    loop.append(now)
    if l[now] == 1:
        loop = loop[loop.index(now):-1]
        break
    else:
        l[now] = 1

if count == K:
    print(now + 1)
else:
    ans = loop[(K-count) % len(loop)]
    print(ans + 1)

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

seen = [-1 for _ in range(N)]
seen[0] = 0
next = 0

# たかだか N 回回ればループに入る
for i in range(min(K, N)+1):
    if seen[next] == -1:
        last = i
        break
    else:
        next = A[next]-1
        seen[i+1] = next

# loop なしの場合
if A[next]-1 not in seen[:min(K, N)]:
    print(A[next])
    exit()

# それ以外
next_ind = seen[:last+1].index(next)
loop = seen[next_ind:last+1]
#print(loop)

mod = (K - next_ind) % len(loop)
ans = loop[mod]+1

print(ans)


Fixed submission:
N, K = map(int, input().split())
A = list(map(int, input().split()))
l = [0 for _ in range(N)]

now = 0
l[now] = 1
count = 0
loop = [0]

while count < K:
    count += 1
    now = A[now]-1
    loop.append(now)
    if l[now] == 1:
        loop = loop[loop.index(now):-1]
        break
    else:
        l[now] = 1

if count == K:
    print(now + 1)
else:
    ans = loop[(K-count) % len(loop)]
    print(ans + 1)