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

costs = [-1] * (N + 1)

loc = 1
costs[loc] = 0
for i in range(1, K):
    loc = A[loc - 1]

    if costs[loc] >= 0:
        break

    costs[loc] = i

offset = costs[loc]
loop = i - offset

K -= i
K %= loop

for _ in range(K):
    loc = A[loc - 1]
print(loc)

Fixed submission:
N, K = map(int, input().split())
A = tuple(map(lambda n: int(n) - 1, input().split()))

costs = [-1] * N
loc = 0

if K <= N:
    for i in range(K):
        loc = A[loc]
    print(loc + 1)

else:
    costs[loc] = 0
    for i in range(1, K):
        loc = A[loc]

        if costs[loc] >= 0:
            break

        costs[loc] = i

    offset = costs[loc]
    loop = i - offset

    K -= i
    K %= loop

    for _ in range(K):
        loc = A[loc]
    print(loc + 1)

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

costs = [0] * (N + 1)

loc = 1
for i in range(1, K+1):
    loc = A[loc - 1]

    if costs[loc] > 0:
        break

    costs[loc] = i

offset = costs[loc]
loop = i - offset

K -= i
K %= loop

for _ in range(K):
    loc = A[loc - 1]
print(loc)

Fixed submission:
N, K = map(int, input().split())
A = tuple(map(lambda n: int(n) - 1, input().split()))

costs = [-1] * N
loc = 0

if K <= N:
    for i in range(K):
        loc = A[loc]
    print(loc + 1)

else:
    costs[loc] = 0
    for i in range(1, K):
        loc = A[loc]

        if costs[loc] >= 0:
            break

        costs[loc] = i

    offset = costs[loc]
    loop = i - offset

    K -= i
    K %= loop

    for _ in range(K):
        loc = A[loc]
    print(loc + 1)

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

costs = [0] * (N + 1)

if K <= N:
    for i in range(1, K+1):
        loc = A[loc - 1]
    print(loc)

else:
    loc = 1
    for i in range(1, K+1):
        loc = A[loc - 1]

        if costs[loc] > 0:
            break

        costs[loc] = i

    offset = costs[loc]
    loop = i - offset

    K -= offset
    K %= loop

    for _ in range(K):
        loc = A[loc - 1]
    print(loc)

Fixed submission:
N, K = map(int, input().split())
A = tuple(map(lambda n: int(n) - 1, input().split()))

costs = [-1] * N
loc = 0

if K <= N:
    for i in range(K):
        loc = A[loc]
    print(loc + 1)

else:
    costs[loc] = 0
    for i in range(1, K):
        loc = A[loc]

        if costs[loc] >= 0:
            break

        costs[loc] = i

    offset = costs[loc]
    loop = i - offset

    K -= i
    K %= loop

    for _ in range(K):
        loc = A[loc]
    print(loc + 1)

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

costs = [0] * (N + 1)

loc = 1
for i in range(1, K+1):
    loc = A[loc - 1]

    if costs[loc] > 0:
        break

    costs[loc] = i

offset = costs[loc]
loop = i - offset

K -= offset
K %= loop

for _ in range(K):
    loc = A[loc - 1]
print(loc)

Fixed submission:
N, K = map(int, input().split())
A = tuple(map(lambda n: int(n) - 1, input().split()))

costs = [-1] * N
loc = 0

if K <= N:
    for i in range(K):
        loc = A[loc]
    print(loc + 1)

else:
    costs[loc] = 0
    for i in range(1, K):
        loc = A[loc]

        if costs[loc] >= 0:
            break

        costs[loc] = i

    offset = costs[loc]
    loop = i - offset

    K -= i
    K %= loop

    for _ in range(K):
        loc = A[loc]
    print(loc + 1)

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

rec = [0] * N
costs = [0] * N

loc = 1
rec[loc-1] = 1

finished = True
for i in range(1, K+1):
    next_loc = A[loc - 1]

    if rec[next_loc - 1] == 1:
        break

    costs[next_loc - 1] = i
    rec[next_loc - 1] = 1
    loc = next_loc

loop_index_cost = costs[next_loc - 1]
loop_cost = i - loop_index_cost

cs = tuple(map(lambda x: x - loop_index_cost, costs))

final_loc = cs.index((K - loop_index_cost) % loop_cost) + 1
print(final_loc)

Fixed submission:
N, K = map(int, input().split())
A = tuple(map(lambda n: int(n) - 1, input().split()))

costs = [-1] * N
loc = 0

if K <= N:
    for i in range(K):
        loc = A[loc]
    print(loc + 1)

else:
    costs[loc] = 0
    for i in range(1, K):
        loc = A[loc]

        if costs[loc] >= 0:
            break

        costs[loc] = i

    offset = costs[loc]
    loop = i - offset

    K -= i
    K %= loop

    for _ in range(K):
        loc = A[loc]
    print(loc + 1)