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

place = 1
road = [0 for i in range(N)]
cycle = 0

road[0] = 1

while K != 0:
    place = A_i[place - 1]
    K -= 1

    if road[place - 1] == 1:
        loop_place = place
        break
    road[place - 1] = 1

while K != 0:
    loop_place = A_i[loop_place - 1]
    cycle += 1

    if place == loop_place:
        break

K = K % cycle

while K != 0:
    place = A_i[place - 1]
    K -= 1

print(place)


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

place = 1
road = [0 for i in range(N)]
cycle = 0

road[0] = 1

while K != 0:
    place = A_i[place - 1]
    K -= 1
    if road[place - 1] == 1:
        loop_place = place
        break
    road[place - 1] = 1

while K != 0:
    loop_place = A_i[loop_place - 1]
    cycle += 1

    if place == loop_place:
        break

if cycle != 0:
    K = K % cycle

while K != 0:
    place = A_i[place - 1]
    K -= 1

print(place)

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

place = 1
road = [0 for i in range(N)]
cycle = 0

road[0] = 1

while K != 0:
    place = A_i[place - 1]
    K -= 1

    if road[place - 1] == 1:
        loop_place = place
        break
    road[place - 1] = 1

while 1:
    loop_place = A_i[loop_place - 1]
    cycle += 1

    if place == loop_place:
        break

K = K % cycle

while K != 0:
    place = A_i[place - 1]
    K -= 1

print(place)


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

place = 1
road = [0 for i in range(N)]
cycle = 0

road[0] = 1

while K != 0:
    place = A_i[place - 1]
    K -= 1
    if road[place - 1] == 1:
        loop_place = place
        break
    road[place - 1] = 1

while K != 0:
    loop_place = A_i[loop_place - 1]
    cycle += 1

    if place == loop_place:
        break

if cycle != 0:
    K = K % cycle

while K != 0:
    place = A_i[place - 1]
    K -= 1

print(place)

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

place = 1
road = []
cycle = 0

while K != 0:
    road.append(place)
    place = A_i[place - 1]
    K -= 1

    if place in road:
        loop_place = place
        break

while 1:
    loop_place = A_i[loop_place - 1]
    cycle += 1

    if place == loop_place:
        break

K = K % cycle

while K != 0:
    place = A_i[place - 1]
    K -= 1

print(place)


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

place = 1
road = [0 for i in range(N)]
cycle = 0

road[0] = 1

while K != 0:
    place = A_i[place - 1]
    K -= 1
    if road[place - 1] == 1:
        loop_place = place
        break
    road[place - 1] = 1

while K != 0:
    loop_place = A_i[loop_place - 1]
    cycle += 1

    if place == loop_place:
        break

if cycle != 0:
    K = K % cycle

while K != 0:
    place = A_i[place - 1]
    K -= 1

print(place)

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

place = 1
road = []
cycle = 0
begin = 0

while K != 0:
    road.append(place)
    place = A_i[place - 1]
    K -= 1

    if place in road:
        cycle = len(road) - road.index(place)
        begin = road.index(place)
        break

K = begin + (K - begin) % cycle

while K !=0:
    place = A_i[place - 1]
    K -= 1

print(place)


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

place = 1
road = [0 for i in range(N)]
cycle = 0

road[0] = 1

while K != 0:
    place = A_i[place - 1]
    K -= 1
    if road[place - 1] == 1:
        loop_place = place
        break
    road[place - 1] = 1

while K != 0:
    loop_place = A_i[loop_place - 1]
    cycle += 1

    if place == loop_place:
        break

if cycle != 0:
    K = K % cycle

while K != 0:
    place = A_i[place - 1]
    K -= 1

print(place)