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

array=map(int,input().split())

A=list(array)
A.insert(0,0)

visit=0
root=[]
visited=1
once=0
while True:
    if visit & (0b1<<visited):
        break
    root.append(visited)
    visit|=0b1<<visited
    once+=1
    visited=A[visited]

roop=root[root.index(visited):]
if K<=once:
    print(root[K])
else:
    order=K-once
    print(roop[order%len(roop)])

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

array=map(int,input().split())

A=list(array)
A.insert(0,0)

visit=0
root=[]
visited=1
once=0
while True:
    if visit & (0b1<<visited):
        break
    root.append(visited)
    visit|=0b1<<visited
    once+=1
    visited=A[visited]

roop=root[root.index(visited):]
if K<once:
    print(root[K])
else:
    order=K-once
    print(roop[order%len(roop)])

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

array=map(int,input().split())

A=list(array)
A.insert(0,0)

visit=0
root=[]
visited=1
once=0
while True:
    if visit & (0b1<<visited):
        break
    root.append(visited)
    visit|=0b1<<visited
    once+=1
    visited=A[visited]

roop=root[root.index(visited):]
print(roop)
if K<=once:
    print(root[K])
else:
    order=K-once
    print(roop[order%len(roop)])

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

array=map(int,input().split())

A=list(array)
A.insert(0,0)

visit=0
root=[]
visited=1
once=0
while True:
    if visit & (0b1<<visited):
        break
    root.append(visited)
    visit|=0b1<<visited
    once+=1
    visited=A[visited]

roop=root[root.index(visited):]
if K<once:
    print(root[K])
else:
    order=K-once
    print(roop[order%len(roop)])

Buggy python submission (verdict: Time Limit Exceeded):
import time
N,K=map(int,input().split())

array=map(int,input().split())

A=list(array)
A.insert(0,0)

visit=[]
visited=1
once=0
while True:
    visit.append(visited)
    once+=1
    if A[visited] in visit:
        break
    visited=A[visited]

roop=visit[visit.index(A[visited]):]
if K<once:
    print(visit[K])
else:
    order=K-once
    print(roop[order%len(roop)])

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

array=map(int,input().split())

A=list(array)
A.insert(0,0)

visit=0
root=[]
visited=1
once=0
while True:
    if visit & (0b1<<visited):
        break
    root.append(visited)
    visit|=0b1<<visited
    once+=1
    visited=A[visited]

roop=root[root.index(visited):]
if K<once:
    print(root[K])
else:
    order=K-once
    print(roop[order%len(roop)])

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())

array=map(int,input().split())

A=[0]
for i in array:
    A.append(i)

visit=[]
visited=1
once=0
while True:
    visit.append(visited)
    once+=1
    if A[visited] in visit:
        break
    visited=A[visited]

roop=visit[visit.index(A[visited]):]
if K<once:
    print(visit[K])
else:
    order=K-once
    print(roop[order%len(roop)])

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

array=map(int,input().split())

A=list(array)
A.insert(0,0)

visit=0
root=[]
visited=1
once=0
while True:
    if visit & (0b1<<visited):
        break
    root.append(visited)
    visit|=0b1<<visited
    once+=1
    visited=A[visited]

roop=root[root.index(visited):]
if K<once:
    print(root[K])
else:
    order=K-once
    print(roop[order%len(roop)])

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())

A=[0]
INPUT=map(int,input().split())
for i in INPUT:
    A.append(i)

dist=[1]
pre=[]
num=0
K_cp=K
while dist:
    tele=dist.pop()
    if tele in pre:
        flg=False
        break
    dist.append(A[tele])
    num+=1
    if num==K:
        flg=True
        break
    pre.append(tele)
    K_cp-=1

if not flg:
    start=pre.index(tele)
    cir=pre[start:]
    cir_len=len(cir)
    dist_num=(K_cp%cir_len)
    dist.append(cir[dist_num])
    flg=True

if flg:
    print(dist.pop())

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

array=map(int,input().split())

A=list(array)
A.insert(0,0)

visit=0
root=[]
visited=1
once=0
while True:
    if visit & (0b1<<visited):
        break
    root.append(visited)
    visit|=0b1<<visited
    once+=1
    visited=A[visited]

roop=root[root.index(visited):]
if K<once:
    print(root[K])
else:
    order=K-once
    print(roop[order%len(roop)])

Buggy python submission (verdict: Time Limit Exceeded):
N,K=map(int,input().split())

A=[0]
INPUT=map(int,input().split())
for i in INPUT:
    A.append(i)

dist=[1]
pre=[]
num=0
K_cp=K
while dist:
    tele=dist.pop()
    if tele in pre:
        flg=False
        break
    dist.append(A[tele])
    num+=1
    if num==K:
        flg=True
        break
    pre.append(tele)
    K_cp-=1

if not flg:
    start=pre.index(tele)
    cir=pre[start:]
    cir_len=len(cir)
    dist_num=(K_cp%cir_len)
    dist.append(cir[dist_num])
    flg=True

if flg:
    print(dist.pop())

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

array=map(int,input().split())

A=list(array)
A.insert(0,0)

visit=0
root=[]
visited=1
once=0
while True:
    if visit & (0b1<<visited):
        break
    root.append(visited)
    visit|=0b1<<visited
    once+=1
    visited=A[visited]

roop=root[root.index(visited):]
if K<once:
    print(root[K])
else:
    order=K-once
    print(roop[order%len(roop)])