Buggy python submission (verdict: Time Limit Exceeded):
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
 
def func1(lst, value):
    return [i for i, x in enumerate(lst) if x == value]
  
temp=1
trace=[1]
circle=[]
for i in range(K):
  temp=A[temp-1]
  ans=func1(trace,temp)
  if len(ans)==1:
    circle.append(i-ans[0]+1)
    #print(circle)
    break
  trace.append(temp)
  #print("temp",temp)
#print((K-i)%len(circle)-1)
if len(circle)!=0:
  amari=(K-i)%circle[0]
  temp=1
  for j in range(i+amari):
    temp=A[temp-1]

print(temp)

Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
 
check=[-1 for i in range(N)]
  
temp=1
circle=[]
for i in range(K):
  temp=A[temp-1]
  if check[temp-1]==-1:
    check[temp-1]=i
  else:
    circle.append(i-check[temp-1])
    #print(circle)
    break
  #print("temp",temp)
#print((K-i)%len(circle)-1)
if len(circle)!=0:
  amari=(K-i)%circle[0]
  temp=1
  for j in range(i+amari):
    temp=A[temp-1] 

print(temp)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

def func1(lst, value):
    return [i for i, x in enumerate(lst) if x == value]
  
temp=1
trace=deque()
trace.append(1)
#trace=[1]
circle=[]
for i in range(K):
  temp=A[temp-1]
  ans=func1(trace,temp)
  if len(ans)==1:
    #print(temp)
    #print(trace.index(temp))
    #start=trace.index(temp)
    for _ in range(ans[0]):
      trace.popleft()
    #circle=trace[ans[0]:]
    circle.append(1)
    #print(circle)
    break
  trace.append(temp)
  #print("temp",temp)
#print((K-i)%len(circle)-1)
if len(circle)!=0:
  amari=(K-i)%len(trace)-1
  print(trace[amari])
else:
  print(temp)

Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
 
check=[-1 for i in range(N)]
  
temp=1
circle=[]
for i in range(K):
  temp=A[temp-1]
  if check[temp-1]==-1:
    check[temp-1]=i
  else:
    circle.append(i-check[temp-1])
    #print(circle)
    break
  #print("temp",temp)
#print((K-i)%len(circle)-1)
if len(circle)!=0:
  amari=(K-i)%circle[0]
  temp=1
  for j in range(i+amari):
    temp=A[temp-1] 

print(temp)

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

def func1(lst, value):
    return [i for i, x in enumerate(lst) if x == value]
  
temp=1
trace=[1]
circle=[]
for i in range(K):
  temp=A[temp-1]
  ans=func1(trace,temp)
  if len(ans)==1:
    #print(temp)
    #print(trace.index(temp))
    #start=trace.index(temp)
    circle=trace[ans[0]:]
    #print(circle)
    break
  trace.append(temp)
  #print("temp",temp)
#print((K-i)%len(circle)-1)
if len(circle)!=0:
  amari=(K-i)%len(circle)-1
  print(circle[amari])
else:
  print(temp)

Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
 
check=[-1 for i in range(N)]
  
temp=1
circle=[]
for i in range(K):
  temp=A[temp-1]
  if check[temp-1]==-1:
    check[temp-1]=i
  else:
    circle.append(i-check[temp-1])
    #print(circle)
    break
  #print("temp",temp)
#print((K-i)%len(circle)-1)
if len(circle)!=0:
  amari=(K-i)%circle[0]
  temp=1
  for j in range(i+amari):
    temp=A[temp-1] 

print(temp)

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

def func1(lst, value):
    return [i for i, x in enumerate(lst) if x == value]
  
temp=1
trace=[1]
for i in range(K):
  temp=A[temp-1]
  ans=func1(trace,temp)
  if len(ans)==1:
    #print(temp)
    #print(trace.index(temp))
    #start=trace.index(temp)
    circle=trace[ans[0]:]
    #print(circle)
    break
  trace.append(temp)
  #print("temp",temp)
#print((K-i)%len(circle)-1)
amari=(K-i)%len(circle)-1
print(circle[amari])


Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
 
check=[-1 for i in range(N)]
  
temp=1
circle=[]
for i in range(K):
  temp=A[temp-1]
  if check[temp-1]==-1:
    check[temp-1]=i
  else:
    circle.append(i-check[temp-1])
    #print(circle)
    break
  #print("temp",temp)
#print((K-i)%len(circle)-1)
if len(circle)!=0:
  amari=(K-i)%circle[0]
  temp=1
  for j in range(i+amari):
    temp=A[temp-1] 

print(temp)

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

temp=1
trace=[1]
for i in range(K):
  temp=A[temp-1]
  if temp in trace:
    #print(temp)
    #print(trace.index(temp))
    start=trace.index(temp)
    circle=trace[start:]
    #print(circle)
    break
  trace.append(temp)
  #print("temp",temp)
#print((K-i)%len(circle)-1)
amari=(K-i)%len(circle)-1
print(circle[amari])

  

Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
 
check=[-1 for i in range(N)]
  
temp=1
circle=[]
for i in range(K):
  temp=A[temp-1]
  if check[temp-1]==-1:
    check[temp-1]=i
  else:
    circle.append(i-check[temp-1])
    #print(circle)
    break
  #print("temp",temp)
#print((K-i)%len(circle)-1)
if len(circle)!=0:
  amari=(K-i)%circle[0]
  temp=1
  for j in range(i+amari):
    temp=A[temp-1] 

print(temp)