Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())
 
a = list(map(int, input().split()))
 
res = [0]
tmp = 0
 
tf = [-1 for i in range(n)]
tf[0] = 0
 
for i in range(n):
    tmp = a[tmp] - 1
    if tf[tmp] != -1:
        start = tmp
        break
    else:
        res = res + [tmp]
        tf[tmp] = i+1
 
lenret = i+1
stridx = tf[start]
 
cycle = lenret - stridx
 
if stridx >= k:
    print(res[k]+1)
    exit()
else:
    k = k - stridx
 
    tmp = k % cycle
 
    print(res[stridx+tmp]+1)

Fixed submission:
n, k = map(int, input().split())

a = list(map(int, input().split()))

res = [0]
tmp = 0

tf = [-1 for i in range(n)]
tf[0] = 0

for i in range(n):
    tmp = a[tmp] - 1
    if tf[tmp] != -1:
        start = tmp
        break
    else:
        res.append(tmp)
        tf[tmp] = i+1

lenret = i+1
stridx = tf[start]

cycle = lenret - stridx

if stridx >= k:
    print(res[k]+1)
    exit()
else:
    k = k - stridx

    tmp = k % cycle

    print(res[stridx+tmp]+1)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

a = list(map(int, input().split()))

res = [0]
tmp = 0

tf = [-1 for i in range(n)]
tf[0] = 0

for i in range(n):
    tmp = a[tmp] - 1
    if tf[tmp] != -1:
        start = tmp
        break
    else:
        res = res + [tmp]
        tf[tmp] = i+1

lenret = i+1
stridx = tf[start]

cycle = lenret - stridx

if stridx >= k:
    print(res[k]+1)
    exit()
else:
    k = k - stridx

    tmp = k % cycle

    print(res[stridx+tmp]+1)


Fixed submission:
n, k = map(int, input().split())

a = list(map(int, input().split()))

res = [0]
tmp = 0

tf = [-1 for i in range(n)]
tf[0] = 0

for i in range(n):
    tmp = a[tmp] - 1
    if tf[tmp] != -1:
        start = tmp
        break
    else:
        res.append(tmp)
        tf[tmp] = i+1

lenret = i+1
stridx = tf[start]

cycle = lenret - stridx

if stridx >= k:
    print(res[k]+1)
    exit()
else:
    k = k - stridx

    tmp = k % cycle

    print(res[stridx+tmp]+1)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

a = list(map(int, input().split()))

res = [0]
tmp = 0

tf = [False for i in range(n)]
tf[0] = True

for i in range(n):
    tmp = a[tmp] - 1
    if tf[tmp]:
        start = tmp
        break
    else:
        res = res + [tmp]
        tf[tmp] = True

lenret = i+1
stridx = res.index(tmp)

cycle = lenret - stridx

if stridx >= k:
    print(res[k]+1)
    exit()
else:
    k = k - stridx

    tmp = k % cycle

    print(res[stridx+tmp]+1)


Fixed submission:
n, k = map(int, input().split())

a = list(map(int, input().split()))

res = [0]
tmp = 0

tf = [-1 for i in range(n)]
tf[0] = 0

for i in range(n):
    tmp = a[tmp] - 1
    if tf[tmp] != -1:
        start = tmp
        break
    else:
        res.append(tmp)
        tf[tmp] = i+1

lenret = i+1
stridx = tf[start]

cycle = lenret - stridx

if stridx >= k:
    print(res[k]+1)
    exit()
else:
    k = k - stridx

    tmp = k % cycle

    print(res[stridx+tmp]+1)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

a = list(map(int, input().split()))

res = [0]
tmp = 0

tf = [False for i in range(n)]
tf[0] = True

for i in range(n):
    tmp = a[tmp] - 1
    if tf[tmp]:
        start = tmp
        break
    else:
        res = res + [tmp]
        tf[tmp] = True

lenret = len(res)
stridx = res.index(start)

cycle = lenret - stridx

if stridx >= k:
    print(res[k]+1)
    exit()
else:
    k = k - stridx

    tmp = k % cycle

    print(res[stridx+tmp]+1)


Fixed submission:
n, k = map(int, input().split())

a = list(map(int, input().split()))

res = [0]
tmp = 0

tf = [-1 for i in range(n)]
tf[0] = 0

for i in range(n):
    tmp = a[tmp] - 1
    if tf[tmp] != -1:
        start = tmp
        break
    else:
        res.append(tmp)
        tf[tmp] = i+1

lenret = i+1
stridx = tf[start]

cycle = lenret - stridx

if stridx >= k:
    print(res[k]+1)
    exit()
else:
    k = k - stridx

    tmp = k % cycle

    print(res[stridx+tmp]+1)

Buggy python submission (verdict: Time Limit Exceeded):
n, k = map(int, input().split())

a = list(map(int, input().split()))

res = [0]
tmp = 0

for i in range(n):
    tmp = a[tmp] - 1
    if tmp in res:
        start = tmp
        break
    else:
        res = res + [tmp]

lenret = len(res)
stridx = res.index(start)

cycle = lenret - stridx

if stridx >= k:
    print(res[k]+1)
    exit()
else:
    k = k - stridx

    tmp = k % cycle

    print(res[stridx+tmp]+1)


Fixed submission:
n, k = map(int, input().split())

a = list(map(int, input().split()))

res = [0]
tmp = 0

tf = [-1 for i in range(n)]
tf[0] = 0

for i in range(n):
    tmp = a[tmp] - 1
    if tf[tmp] != -1:
        start = tmp
        break
    else:
        res.append(tmp)
        tf[tmp] = i+1

lenret = i+1
stridx = tf[start]

cycle = lenret - stridx

if stridx >= k:
    print(res[k]+1)
    exit()
else:
    k = k - stridx

    tmp = k % cycle

    print(res[stridx+tmp]+1)