Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
alist = list(map(int,input().split()))
memo = []
p = 1
vis = ['.']*n
while vis[p-1] == '.':
    memo.append(p)
    vis[p-1] = 'v'
    p = alist[p-1]

loop = memo.index(p)
if k < len(alist):
    print(memo[k])
else:
    print(memo[loop+(k-loop)%(len(memo)-loop)])


Fixed submission:
n,k = map(int,input().split())
alist = list(map(int,input().split()))
memo = []
p = 1
vis = ['.']*n
while vis[p-1] == '.':
    memo.append(p)
    vis[p-1] = 'v'
    p = alist[p-1]

loop = memo.index(p)
if k < len(memo):
    print(memo[k])
else:
    print(memo[loop+(k-loop)%(len(memo)-loop)])

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

memo = []
p = 1
vis = ['.']*n

while vis[p-1] == '.':
    memo.append(p)
    vis[p-1] = 'v'
    p = alist[p-1]

loopstart = memo.index(p)
if k < len(alist):
    print(memo[k])
else:
    print(memo[loopstart+(k-loopstart)%(len(memo)-loopstart)])


Fixed submission:
n,k = map(int,input().split())
alist = list(map(int,input().split()))
memo = []
p = 1
vis = ['.']*n
while vis[p-1] == '.':
    memo.append(p)
    vis[p-1] = 'v'
    p = alist[p-1]

loop = memo.index(p)
if k < len(memo):
    print(memo[k])
else:
    print(memo[loop+(k-loop)%(len(memo)-loop)])

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

memo = []
p = 1
vis = ['.']*n

while vis[p-1] == '.':
    memo.appened(p)
    vis[p-1] = 'v'
    p = alist[p-1]

loopstart = alist.index(p)
if k < len(alist):
    print(memo[k])
else:
    print(memo[loopstart+(k-loopstart)%(len(alist)-loopstart)])


Fixed submission:
n,k = map(int,input().split())
alist = list(map(int,input().split()))
memo = []
p = 1
vis = ['.']*n
while vis[p-1] == '.':
    memo.append(p)
    vis[p-1] = 'v'
    p = alist[p-1]

loop = memo.index(p)
if k < len(memo):
    print(memo[k])
else:
    print(memo[loop+(k-loop)%(len(memo)-loop)])

Buggy python submission (verdict: Runtime Error):
from collections import deque
n,k = map(int,input().split())
alist = list(map(int,input().split()))


flag = ['.']*(n+1)
flag[1] = 'v'

been = [1]

for i in range(k):
    goto = alist[been[-1]-1]
    if flag[goto] == '.':
        been.append(goto)
        flag[goto] = 'v'
    else:
        loopstart = goto
        break
loop = been[been.index(loopstart):]

print(loop[(k+1-loopstart)%(len(loop)+been.index(loopstart))])


Fixed submission:
n,k = map(int,input().split())
alist = list(map(int,input().split()))
memo = []
p = 1
vis = ['.']*n
while vis[p-1] == '.':
    memo.append(p)
    vis[p-1] = 'v'
    p = alist[p-1]

loop = memo.index(p)
if k < len(memo):
    print(memo[k])
else:
    print(memo[loop+(k-loop)%(len(memo)-loop)])

Buggy python submission (verdict: Runtime Error):
from collections import deque
n,k = map(int,input().split())
alist = list(map(int,input().split()))


flag = ['.']*(n+1)
flag[1] = 'v'

been = [1]

for i in range(k):
    goto = alist[been[-1]-1]
    if flag[goto] == '.':
        been.append(goto)
        flag[goto] = 'v'
    else:
        loopstart = goto
        break
loop = been[been.index(loopstart):]
print(loop[(k-loopstart)%len(loop)])



Fixed submission:
n,k = map(int,input().split())
alist = list(map(int,input().split()))
memo = []
p = 1
vis = ['.']*n
while vis[p-1] == '.':
    memo.append(p)
    vis[p-1] = 'v'
    p = alist[p-1]

loop = memo.index(p)
if k < len(memo):
    print(memo[k])
else:
    print(memo[loop+(k-loop)%(len(memo)-loop)])