Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
A=list(map(int, input().split()))
now = 1
if n>=k:
    for i in k:
        now = A[now-1]
        exit()
past = [-1]*n
cnt = 0
while now not in past:
    past[cnt] = now
    now = A[now-1]
    cnt +=1
loop_size = cnt-past.index(now)
surplus = (k-past.index(now))%loop_size
for i in range(surplus):
    now = A[now-1]
print(now)

Fixed submission:
n,k = map(int, input().split())
b = list(map(int, input().split()))
a=0
for i in range(n):
    b[i] -= 1
if k<n:
    for i in range(k):
        a = b[a]
    print(a+1)
    exit()
c = [-1]*n
cc = 0
se = set()
while a not in se:
    c[a] = cc
    cc += 1
    se.add(a)
    a = b[a]
for i in range((k-c[a])%(cc-c[a])):
    a = b[a]
print(a+1)

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
A=list(map(int, input().split()))
now = 1
if n>=k:
    for i in k:
        now = A[now-1]
        exit()
past = []
while now not in past:
    past.append(now)
    now = A[now-1]
loop_size = len(past)-past.index(now)
surplus = (k-past.index(now))%loop_size
for i in range(surplus):
    now = A[now-1]
print(now)

Fixed submission:
n,k = map(int, input().split())
b = list(map(int, input().split()))
a=0
for i in range(n):
    b[i] -= 1
if k<n:
    for i in range(k):
        a = b[a]
    print(a+1)
    exit()
c = [-1]*n
cc = 0
se = set()
while a not in se:
    c[a] = cc
    cc += 1
    se.add(a)
    a = b[a]
for i in range((k-c[a])%(cc-c[a])):
    a = b[a]
print(a+1)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
A = list(map(int, input().split()))
now = 1
f = 0
past = [0]*n
if n>k:
	for i in range(k):
		now = A[now-1]
	print(now)
	exit()
c = 0
for i in range(n):
	past[c] = now
	now = A[now-1]
	c+=1
	if now in past:
		f = 1
		break


loop_end = c
loop_start = past.index(now)
#print(past, now, loop_end, loop_start)
res = (k-loop_start)%(loop_end-loop_start)
now = past[loop_start]
for i in range(res):
	now = A[now-1]
print(now)


Fixed submission:
n,k = map(int, input().split())
b = list(map(int, input().split()))
a=0
for i in range(n):
    b[i] -= 1
if k<n:
    for i in range(k):
        a = b[a]
    print(a+1)
    exit()
c = [-1]*n
cc = 0
se = set()
while a not in se:
    c[a] = cc
    cc += 1
    se.add(a)
    a = b[a]
for i in range((k-c[a])%(cc-c[a])):
    a = b[a]
print(a+1)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
A = list(map(int, input().split()))
now = 1
f = 0
past = [0]*n
if n>k:
	for i in range(k):
		now = A[now-1]
	print(now)
	exit()
c = 0
for i in range(n):
	past[c] = now
	now = A[now-1]
	c+=1
	if now in past:
		f = 1
		break


loop_end = c
loop_start = past.index(now)
#print(past, now, loop_end, loop_start)
res = (k-loop_start)%(loop_end-loop_start)
now = past[loop_start]
for i in range(res):
	now = A[now-1]
print(now)

Fixed submission:
n,k = map(int, input().split())
b = list(map(int, input().split()))
a=0
for i in range(n):
    b[i] -= 1
if k<n:
    for i in range(k):
        a = b[a]
    print(a+1)
    exit()
c = [-1]*n
cc = 0
se = set()
while a not in se:
    c[a] = cc
    cc += 1
    se.add(a)
    a = b[a]
for i in range((k-c[a])%(cc-c[a])):
    a = b[a]
print(a+1)

Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
A = list(map(int, input().split()))
now = 1
f = 0
past = [0]*k
if n>k:
	for i in range(k):
		now = A[now-1]
	print(now)
	exit()
c = 0
for i in range(n):
	past[c] = now
	now = A[now-1]
	c+=1
	if now in past:
		f = 1
		break


loop_end = c
loop_start = past.index(now)
#print(past, now, loop_end, loop_start)
res = (k-loop_start)%(loop_end-loop_start)
now = past[loop_start]
for i in range(res):
	now = A[now-1]
print(now)

Fixed submission:
n,k = map(int, input().split())
b = list(map(int, input().split()))
a=0
for i in range(n):
    b[i] -= 1
if k<n:
    for i in range(k):
        a = b[a]
    print(a+1)
    exit()
c = [-1]*n
cc = 0
se = set()
while a not in se:
    c[a] = cc
    cc += 1
    se.add(a)
    a = b[a]
for i in range((k-c[a])%(cc-c[a])):
    a = b[a]
print(a+1)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int, input().split())
A = list(map(int, input().split()))
import collections
res = collections.deque('1')
rep = [0,0]
for i in range(n):
    #print(res)
    if str(A[int(res[-1])-1]) not in res:
        res.append(str(A[int(res[-1])-1]))
    else:
        rep[0] = res.index(str(A[int(res[-1])-1]))
        rep[1] = len(res)
        break

#print(res)
#print(rep)
if k < len(res):
    print(res[k])
else:
    rep_num = rep[1] - rep[0]
    remainder = (k-rep[0])%rep_num
    print(res[rep[0] +remainder])

Fixed submission:
n,k = map(int, input().split())
b = list(map(int, input().split()))
a=0
for i in range(n):
    b[i] -= 1
if k<n:
    for i in range(k):
        a = b[a]
    print(a+1)
    exit()
c = [-1]*n
cc = 0
se = set()
while a not in se:
    c[a] = cc
    cc += 1
    se.add(a)
    a = b[a]
for i in range((k-c[a])%(cc-c[a])):
    a = b[a]
print(a+1)

Buggy python submission (verdict: Runtime Error):
n,k = map(int, input().split())
A = list(map(int, input().split()))
import collections
res = collections.deque('1')
rep = [0,0]
for i in range(n):
    print(res)
    if str(A[int(res[-1])-1]) not in res:
        res.append(str(A[int(res[-1])-1]))
    else:
        rep[0] = res.index(str(A[int(res[-1])-1]))
        rep[1] = len(res)
        break

#print(res)
#print(rep)
if k < len(res):
    print(res[k])
else:
    rep_num = rep[1] - rep[0]
    remainder = (k-rep[0])%rep_num
    print(res[rep[0] +remainder])

Fixed submission:
n,k = map(int, input().split())
b = list(map(int, input().split()))
a=0
for i in range(n):
    b[i] -= 1
if k<n:
    for i in range(k):
        a = b[a]
    print(a+1)
    exit()
c = [-1]*n
cc = 0
se = set()
while a not in se:
    c[a] = cc
    cc += 1
    se.add(a)
    a = b[a]
for i in range((k-c[a])%(cc-c[a])):
    a = b[a]
print(a+1)