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

start = 0
atesaki = 0
atesaki_li = [0]
target = atesaki
last = -1
for i in range(k):
    atesaki = li[start]-1
    start = atesaki
    if atesaki in atesaki_li:
        last = atesaki
        break
    else:
        atesaki_li.append(atesaki)
#print(last,atesaki_li)
#[0, 2, 3]

ma = len(atesaki_li)
if k+1<=ma:
    print(ma[k])
else:
    fi = atesaki_li.index(last)
    kurikaeshi = ma - fi
    ama = (k+1-ma)%kurikaeshi
    new_li = atesaki_li[fi:]
    #print(fi,kurikaeshi,ama,atesaki_li)
    #print(atesaki_li,last,kurikaeshi,ama)
    #print(new_li)
    print(new_li[ama-1]+1)


Fixed submission:
n,k = map(int,input().split())
li = [0]+list(map(int,input().split()))

memo = [-1]*(n+1)
start = 1
syuuki = 0
haji = 0

for i in range(k):
    if memo[start] != -1:
        syuuki = i - memo[start]
        haji = memo[start]
        break
    memo[start] = i
    start = li[start]
else:
    print(start)
    exit()

#print(syuuki,haji)
k-=haji
k%=syuuki
k+=haji

start = 1
for kk in range(k):
    start = li[start]
print(start)

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

start = 0
atesaki = 0
atesaki_li = [0]
target = atesaki
last = -1
for i in range(k):
    atesaki = li[start]-1
    start = atesaki
    if atesaki in atesaki_li:
        last = atesaki
        break
    else:
        atesaki_li.append(atesaki)
#print(last,atesaki_li)
#[0, 2, 3]

ma = len(atesaki_li)
if k+1<=ma:
    print(ma[k])
else:
    fi = atesaki_li.index(last)
    kurikaeshi = ma - fi
    ama = (k+1-ma)%kurikaeshi
    #print(fi,ama,atesaki_li)
    print(atesaki_li[(fi-1)+ama]+1)

Fixed submission:
n,k = map(int,input().split())
li = [0]+list(map(int,input().split()))

memo = [-1]*(n+1)
start = 1
syuuki = 0
haji = 0

for i in range(k):
    if memo[start] != -1:
        syuuki = i - memo[start]
        haji = memo[start]
        break
    memo[start] = i
    start = li[start]
else:
    print(start)
    exit()

#print(syuuki,haji)
k-=haji
k%=syuuki
k+=haji

start = 1
for kk in range(k):
    start = li[start]
print(start)

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

start = 0
atesaki = 0
atesaki_li = [0]
target = atesaki
last = -1
for i in range(k):
    atesaki = li[start]-1
    start = atesaki
    if atesaki in atesaki_li:
        last = atesaki
        break
    else:
        atesaki_li.append(atesaki)
#print(last,atesaki_li)
#[0, 2, 3]

ma = len(atesaki_li)
if k+1<=ma:
    print(ma[k])
else:
    fi = atesaki_li.index(last)
    kurikaeshi = ma - fi
    ama = (k+1-ma)%kurikaeshi
    #print(fi,ama,atesaki_li)
    print(atesaki_li[(fi-1)+ama]+1)

Fixed submission:
n,k = map(int,input().split())
li = [0]+list(map(int,input().split()))

memo = [-1]*(n+1)
start = 1
syuuki = 0
haji = 0

for i in range(k):
    if memo[start] != -1:
        syuuki = i - memo[start]
        haji = memo[start]
        break
    memo[start] = i
    start = li[start]
else:
    print(start)
    exit()

#print(syuuki,haji)
k-=haji
k%=syuuki
k+=haji

start = 1
for kk in range(k):
    start = li[start]
print(start)

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

start = 0
atesaki = 0
start_li = [0]
atesaki_li = []
count = 0
target = atesaki
for i in range(k):
    atesaki = li[start]-1
    start = atesaki
    if atesaki in atesaki_li:
        count = i+1
        break
    else:
        atesaki_li.append(atesaki)
    #print(atesaki,'tes')

first_ind = atesaki_li.index(atesaki)+1
#print(atesaki_li,atesaki,first_ind)

atesaki_li[(k-len(atesaki_li))%(len(atesaki_li)-first_ind+1)]
print(atesaki_li[(k-len(atesaki_li))%(len(atesaki_li)-first_ind+1)])+1

Fixed submission:
n,k = map(int,input().split())
li = [0]+list(map(int,input().split()))

memo = [-1]*(n+1)
start = 1
syuuki = 0
haji = 0

for i in range(k):
    if memo[start] != -1:
        syuuki = i - memo[start]
        haji = memo[start]
        break
    memo[start] = i
    start = li[start]
else:
    print(start)
    exit()

#print(syuuki,haji)
k-=haji
k%=syuuki
k+=haji

start = 1
for kk in range(k):
    start = li[start]
print(start)