Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move[k]) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)


Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)

Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = A[pos] - 1
if len(move[k]) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
n,k = map(int,input().split())
a = list(map(int,input().split()))
roop_find_list = [0]
i = 0
count = 0
for _ in range(n):
    if a[i]-1 in roop_find_list:
        break
    else:
        roop_find_list.append(a[i]-1)
        i = a[i] - 1
        count += 1
b = roop_find_list.index(a[i]-1)

if k < b:
    print(roop_find_list[k]+1)
else:
    k-=b
    e = k % (count+1-b)
    print(roop_find_list[b+e]+1)


Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import numpy as np
n,k = map(int,input().split())
a = list(map(int,input().split()))
roop_find = deque([0])
i = 0
count = 0
for _ in range(n):
    if a[i]-1 in roop_find:
        break
    else:
        roop_find.append(a[i]-1)
        i = a[i] - 1
        count += 1
b = roop_find.index(a[i]-1)

if k < b:
    print(roop_find[k]+1)
else:
    k-=b
    e = k % (count+1-b)
    print(roop_find[b+e]+1)


Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import numpy as np
n,k = map(int,input().split())
a = list(map(int,input().split()))
roop_find = deque([0])
i = 0
count = 0
for _ in range(n):
    if a[i]-1 in roop_find:
        break
    else:
        roop_find.append(a[i]-1)
        i = a[i] - 1
        count += 1
b = roop_find.index(a[i]-1)

if k < b:
    print(list(roop_find)[k]+1)
else:
    k-=b
    e = k % (count+1-b)
    print(list(roop_find)[b+e]+1)


Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import numpy as np
n,k = map(int,input().split())
a = list(map(int,input().split()))
roop_find = deque([0])
i = 0
count = 0
while a[i]-1 not in roop_find:
    roop_find.append(a[i]-1)
    i = a[i] - 1
    count += 1
b = roop_find.index(a[i]-1)

if k < b:
    print(list(roop_find)[k]+1)
else:
    k-=b
    e = k % (count+1-b)
    print(roop_find[b+e]+1)


Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)

Buggy python submission (verdict: Runtime Error):
from collections import deque
import numpy as np
n,k = map(int,input().split())
a = list(map(int,input().split()))
roop_find = deque([0])
i = 0
count = 0
while a[i]-1 not in roop_find:
    roop_find.append(a[i]-1)
    i = a[i] - 1
    count += 1
    if count == k:
        print(i + 1)
        break
    else:
        pass
if b < k:
    b = roop_find.index(a[i]-1)
    roop = list(roop_find)[b:count+1]

    k -= b
    e = k % (count+1-b)
    print(roop[e]+1)


Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)

Buggy python submission (verdict: Runtime Error):
from collections import deque
import numpy as np
n,k = map(int,input().split())
a = list(map(int,input().split()))
roop_find = deque([0])
i = 0
count = 0
while a[i]-1 not in roop_find:
    roop_find.append(a[i]-1)
    i = a[i] - 1
    count += 1
    if count == k:
        print(i + 1)
        break
    else:
        pass
if b <= k:
    b = roop_find.index(a[i]-1)
    roop = list(roop_find)[b:count+1]

    k -= b
    e = k % (count+1-b)
    print(roop[e]+1)


Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)

Buggy python submission (verdict: Runtime Error):
from collections import deque
import numpy as np
n,k = map(int,input().split())
a = list(map(int,input().split()))
roop_find = deque([0])
i = 0
count = 0
while a[i]-1 not in roop_find:
    roop_find.append(a[i]-1)
    i = a[i] - 1
    count += 1
    if count == k:
        print(i + 1)
        break
    else:
        pass
b = roop_find.index(a[i]-1)
roop = list(roop_find)[b:count+1]
if b < k:
    k -= b
    e = k % (count+1-b)
    print(roop[e]+1)


Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)

Buggy python submission (verdict: Runtime Error):
from collections import deque
import numpy as np
n,k = map(int,input().split())
a = list(map(int,input().split()))
roop_find = deque([0])
i = 0
count = 0
while a[i]-1 not in roop_find:
    roop_find.append(a[i]-1)
    i = a[i] - 1
    count += 1
    if count == k:
        ans = print(i + 1)
        break
    else:
        pass
b = roop_find.index(a[i]-1)
roop = list(roop_find)[b:count+1]
if b < k:
    k -= b
    e = k % (count+1-b)
    print(roop[e]+1)


Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)

Buggy python submission (verdict: Runtime Error):
from collections import deque
import numpy as np
n,k = map(int,input().split())
a = list(map(int,input().split()))
roop_find = deque([0])
i = 0
count = 0
while a[i]-1 not in roop_find:
    roop_find.append(a[i]-1)
    i = a[i] - 1
    count += 1
    if count == k:
        print(i+1)
        break
    else:
        pass
b = roop_find.index(a[i]-1)
roop = list(roop_find)[b:count+1]
k-=b
e = k % (count+1-b)
print(roop[e]+1)


Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)

Buggy python submission (verdict: Time Limit Exceeded):
from collections import deque
import numpy as np
n,k = map(int,input().split())
a = list(map(int,input().split()))
roop_find = deque([0])
i = 0
count = 0
while a[i]-1 not in roop_find:
    roop_find.append(a[i]-1)
    i = a[i] - 1
    count += 1
b = roop_find.index(a[i]-1)
roop = list(np.array(roop_find)[b:count+1])

if k < b:
    print(list(roop_find)[k]+1)
else:
    k-=b
    e = k % (count+1-b)
    print(roop[e]+1)


Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)

Buggy python submission (verdict: Runtime Error):
from collections import deque
n,k = map(int,input().split())
a = list(map(int,input().split()))
roop_find = deque([0])
i = 0
count = 0
while a[i]-1 not in roop_find:
    roop_find.append(a[i]-1)
    i = a[i] - 1
    count += 1
b = roop_find.index(a[i]-1)
roop = list(roop_find)[b:count+1]

if k < b:
    print(roop_f[k]+1)
else:
    k-=b
    e = k % len(roop)
    print(roop[e]+1)


Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)

Buggy python submission (verdict: Time Limit Exceeded):
n,k = map(int,input().split())
a = list(map(int,input().split()))
roop_find = [0]
check = [0]
i = 0
count = 0
while a[i]-1 not in roop_find:
    roop_find.append(a[i]-1)
    i = a[i] - 1
    count += 1
b = roop_find.index(a[i]-1)
root = roop_find[b:count+1]

if k < b:
    print(roop_find[k]+1)
else:
    k-=b
    e = k % len(root)
    print(root[e]+1)


Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
pos = 0
visit = [0] * n
move = []
loop = []
while visit[pos] != 2:
    if visit[pos] == 0:
        move.append(pos)
    else:
        loop.append(pos)
    visit[pos] += 1
    pos = a[pos] - 1
if len(move) > k:
    print(move[k]+1)
else:
    print(loop[(k-(len(move)-len(loop)))%len(loop)]+1)