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

from collections import deque 
tmp = 1
num = deque()
A_list = deque([[] for i in range(N+1)])
 
for i in range(N):
    num.append(tmp)
    A_list[tmp].append(i)
    if tmp == A[tmp-1]:
        judge = tmp
        flag1 = 1
        break
    tmp = A[tmp-1]
    if tmp in num:
        judge = tmp
        flag2 = 1
        break

if flag2 == 1:
    num_index = A_list[judge]
    print(num[(K-num_index[0])%(len(num)-num_index[0]) + num_index[0]])
elif flag1 == 1:
    if K > len(num):
        print(judge)
    else:
        print(num[K-1])

Fixed submission:
N,K = map(int,input().split())
A = [0] + list(map(int,input().split()))

from collections import deque 
tmp = 1
num = []
seen = [-1]*(N+1)
 
while seen[tmp] == -1:
    seen[tmp] = tmp
    num.append(tmp)
    tmp = A[tmp]


l = num.index(tmp)
c = len(num) - l

if K < l:
    print(num[K])
else:
    print(num[(K-l)%c+l])

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

from collections import deque 
tmp = 1
num = deque()
A_list = [[] for i in range(N+1)]
 
for i in range(N):
    num.append(tmp)
    A_list[tmp].append(i)
    if tmp == A[tmp-1]:
        judge = tmp
        flag1 = 1
        break
    tmp = A[tmp-1]
    if tmp in num:
        judge = tmp
        flag2 = 1
        break

if flag2 == 1:
    num_index = A_list[judge]
    print(num[(K-num_index[0])%(len(num)-num_index[0]) + num_index[0]])
elif flag1 == 1:
    if K >= len(num):
        print(judge)
    else:
        print(num[K-1])

Fixed submission:
N,K = map(int,input().split())
A = [0] + list(map(int,input().split()))

from collections import deque 
tmp = 1
num = []
seen = [-1]*(N+1)
 
while seen[tmp] == -1:
    seen[tmp] = tmp
    num.append(tmp)
    tmp = A[tmp]


l = num.index(tmp)
c = len(num) - l

if K < l:
    print(num[K])
else:
    print(num[(K-l)%c+l])

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

from collections import deque 
tmp = 1
num = deque()
 
for i in range(N):
    num.append(tmp)
    if tmp == A[tmp-1]:
        judge = tmp
        flag1 = 1
        break
    tmp = A[tmp-1]
    if tmp in num:
        judge = tmp
        flag2 = 1
        break

if flag2 == 1:
    num_index = num.index(judge)
    print(num[(K-num_index)%(len(num)-num_index) + num_index])
elif flag1 == 1:
    if K >= len(num):
        print(judge)
    else:
        print(num[K-1])

Fixed submission:
N,K = map(int,input().split())
A = [0] + list(map(int,input().split()))

from collections import deque 
tmp = 1
num = []
seen = [-1]*(N+1)
 
while seen[tmp] == -1:
    seen[tmp] = tmp
    num.append(tmp)
    tmp = A[tmp]


l = num.index(tmp)
c = len(num) - l

if K < l:
    print(num[K])
else:
    print(num[(K-l)%c+l])

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

from collections import deque 
tmp = 1
num = deque()
 
for i in range(N):
    num.append(tmp)
    if tmp == A[tmp-1]:
        judge = tmp
        flag1 = 1
        break
    tmp = A[tmp-1]
    if tmp in num:
        judge = tmp
        flag2 = 1
        break
print(num)

if flag2 == 1:
    print(num[(K-num.index(judge))%(len(num)-num.index(judge)) + num.index(judge)])
elif flag1 == 1:
    if K >= len(num):
        print(judge)
    else:
        print(num[K-1])

Fixed submission:
N,K = map(int,input().split())
A = [0] + list(map(int,input().split()))

from collections import deque 
tmp = 1
num = []
seen = [-1]*(N+1)
 
while seen[tmp] == -1:
    seen[tmp] = tmp
    num.append(tmp)
    tmp = A[tmp]


l = num.index(tmp)
c = len(num) - l

if K < l:
    print(num[K])
else:
    print(num[(K-l)%c+l])