Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
a = [0] +  list(map(int,input().split()))

vlist = [1]
vcnt = [0]*(n+1)
vcnt[1] += 1
v = 1
for i in range(1,n+1):
    v = a[v]
    vlist.append(v)
    if i == k:
        print(vlist[-1])
        exit()
    if vcnt[v] == 0:
        vcnt[v] += i
    else:
        syuuki = i - vcnt[v]
        hajime = i - syuuki
        break
k -= hajime
k %= syuuki
k += hajime 
print(vlist[k])

Fixed submission:
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
alist = list(map(lambda x:int(x) - 1,input().split()))
count = [0]*n
count[0] += 1
now = 0
order = [0]
for i in range(k):
    now = alist[now]
    count[now] += 1
    if count[now] == 2:
        start = order.index(now)
        loop = len(order[start:])
        syoki = len(order[:start])
        break
    order.append(now)
else:
    print(now+1)
    exit()
k -= syoki
k %= loop
print(order[k+syoki] + 1)

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = [0] + list(map(int,input().split()))
vcnt = [0]*(n+1)
vcnt[1] += 1
v = 1
sentou = 0
slist = []
vlist = [1]
hajime = 10**10
for i in range(1,k+1):
    v = a[v]
    vlist.append(v)
    vcnt[v] += 1
    if sentou > 0:
        syuuki += 1
    if vcnt[v] == 2:
        syuuki = 1
        sentou = a[v]
        slist.append(v)
    if vcnt[v] == 3:
        syuuki += 1
        hajime = i - syuuki*2
        break
else:
    print(v)
    exit()
#print(syuuki,hajime,sentou)
#print(slist)
k -= hajime
#print(slist)
slist = [0] + slist
if (k+1)%syuuki == 0:
    print(slist[-1])
else:
    print(slist[(k+1)%syuuki])

Fixed submission:
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
alist = list(map(lambda x:int(x) - 1,input().split()))
count = [0]*n
count[0] += 1
now = 0
order = [0]
for i in range(k):
    now = alist[now]
    count[now] += 1
    if count[now] == 2:
        start = order.index(now)
        loop = len(order[start:])
        syoki = len(order[:start])
        break
    order.append(now)
else:
    print(now+1)
    exit()
k -= syoki
k %= loop
print(order[k+syoki] + 1)

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = [0] + list(map(int,input().split()))
vcnt = [0]*(n+1)
vcnt[1] += 1
v = 1
sentou = 0
slist = []
vlist = [1]
hajime = 10**10
for i in range(1,k+1):
    v = a[v]
    vlist.append(v)
    vcnt[v] += 1
    if sentou > 0:
        syuuki += 1
    if vcnt[v] == 2:
        syuuki = 1
        sentou = a[v]
        slist.append(v)
    if vcnt[v] == 3:
        syuuki += 1
        hajime = i - syuuki*2
        break
else:
    print(v)
    exit()
#print(syuuki,hajime,sentou)
#print(slist)
k -= hajime
print(slist)
slist = [0] + slist
if (k+1)%syuuki == 0:
    print(slist[-1])
else:
    print(slist[(k+1)%syuuki])

Fixed submission:
import sys
input = sys.stdin.readline
n,k = map(int,input().split())
alist = list(map(lambda x:int(x) - 1,input().split()))
count = [0]*n
count[0] += 1
now = 0
order = [0]
for i in range(k):
    now = alist[now]
    count[now] += 1
    if count[now] == 2:
        start = order.index(now)
        loop = len(order[start:])
        syoki = len(order[:start])
        break
    order.append(now)
else:
    print(now+1)
    exit()
k -= syoki
k %= loop
print(order[k+syoki] + 1)