Buggy python submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
t = list(map(int, input().split()))

visited = [False]*(2*10**5 + 10)
val = 1
count = 0
hold = k
while hold > 0 :
    if visited[val - 1] or val == t[val - 1]:
        break
    visited[val - 1] = True
    val = t[val - 1]
    # print('a', val)
    count += 1
    hold -= 1
if hold == 0:
    print(t[val - 1])
    exit(0)
if val == t[val - 1]:
    print(1/0)
    exit(0)
count0 = count
count = 1
newval = val
start = t[newval - 1]
while start != newval:
    count += 1
    start = t[start - 1]
# print('count', count, 'count0', count0)
if t[val - 1] == t[0]:
    temp = k
else:
    temp = k - count0
# print('temp', temp)
jump = (temp) % (count)
# print('jump', jump)
# print('val', val)
ans = val
for i in range(jump):
    ans = t[ans - 1]
    # print('b', ans)
print(ans)

Fixed submission:
n, k = list(map(int, input().split()))
t = list(map(int, input().split()))

visited = [False]*(2*10**5 + 10)
val = 1
count = 0
hold = k
while hold > 0 :
    if visited[val - 1] or val == t[val - 1]:
        break
    visited[val - 1] = True
    val = t[val - 1]
    # print('a', val)
    count += 1
    hold -= 1
# print(hold)
if hold == 0:
    print(val)
    exit(0)
if val == t[val - 1]:
    print(val)
    exit(0)
count0 = count
count = 1
newval = val
start = t[newval - 1]
while start != newval:
    count += 1
    start = t[start - 1]
# print('count', count, 'count0', count0)
if t[val - 1] == t[0]:
    temp = k
else:
    temp = k - count0
# print('temp', temp)
jump = (temp) % (count)
# print('jump', jump)
# print('val', val)
ans = val
for i in range(jump):
    ans = t[ans - 1]
    # print('b', ans)
print(ans)

Buggy python submission (verdict: Runtime Error):
n, k = list(map(int, input().split()))
t = list(map(int, input().split()))

visited = [False]*(2*10**5 + 10)
val = 1
count = 0
hold = k
while hold > 0 :
    if visited[val - 1] or val == t[val - 1]:
        break
    visited[val - 1] = True
    val = t[val - 1]
    # print('a', val)
    count += 1
    hold -= 1
if hold == 0:
    print(1/0)
    exit(0)
if val == t[val - 1]:
    print(1/0)
    exit(0)
count0 = count
count = 1
newval = val
start = t[newval - 1]
while start != newval:
    count += 1
    start = t[start - 1]
# print('count', count, 'count0', count0)
if t[val - 1] == t[0]:
    temp = k
else:
    temp = k - count0
# print('temp', temp)
jump = (temp) % (count)
# print('jump', jump)
# print('val', val)
ans = val
for i in range(jump):
    ans = t[ans - 1]
    # print('b', ans)
print(ans)

Fixed submission:
n, k = list(map(int, input().split()))
t = list(map(int, input().split()))

visited = [False]*(2*10**5 + 10)
val = 1
count = 0
hold = k
while hold > 0 :
    if visited[val - 1] or val == t[val - 1]:
        break
    visited[val - 1] = True
    val = t[val - 1]
    # print('a', val)
    count += 1
    hold -= 1
# print(hold)
if hold == 0:
    print(val)
    exit(0)
if val == t[val - 1]:
    print(val)
    exit(0)
count0 = count
count = 1
newval = val
start = t[newval - 1]
while start != newval:
    count += 1
    start = t[start - 1]
# print('count', count, 'count0', count0)
if t[val - 1] == t[0]:
    temp = k
else:
    temp = k - count0
# print('temp', temp)
jump = (temp) % (count)
# print('jump', jump)
# print('val', val)
ans = val
for i in range(jump):
    ans = t[ans - 1]
    # print('b', ans)
print(ans)