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

now=1
flg = 0
path=[1]
for i in range(k):
    now = a[now-1]
    if now in path:
        flg = -1
        path.append(now)
        break
    path.append(now)

if flg == 0:
    print(now)
    exit()

x1 = path.index(now)
x2 = len(path)-1
x3 = (k-x1)%(x2-x1)
print(path[x1+x3])



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

now=1
flg = 0
path = [1]
pathcheck ={1}
for i in range(k):
    now = a[now-1]
    if now in pathcheck:
        flg = -1
        path.append(now)
        break
    path.append(now)
    pathcheck.add(now)


if flg == 0:
    print(now)
    exit()

x1 = path.index(now)
x2 = len(path)-1
x3 = (k-x1)%(x2-x1)
print(path[x1+x3])

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

now=1
flg = 0
path=[1]
for i in range(k):
    now = a[now-1]
    if now in path:
        flg = -1
        path.append(now)
        break
    path.append(now)

if flg == 0:
    print(now)
    exit()

x1 = path.index(now)
x2 = len(path)-1
x3 = (k-x1)%(x2-x1)
print(path[x1+x3])



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

now=1
flg = 0
path = [1]
pathcheck ={1}
for i in range(k):
    now = a[now-1]
    if now in pathcheck:
        flg = -1
        path.append(now)
        break
    path.append(now)
    pathcheck.add(now)


if flg == 0:
    print(now)
    exit()

x1 = path.index(now)
x2 = len(path)-1
x3 = (k-x1)%(x2-x1)
print(path[x1+x3])

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

flg = 0
now=1
path=[1]
while flg < k:
    flg = flg+1
    now = a[now-1]
    if now in path:
        flg=k+1
    path.append(now)

if flg == k:
    print(now)
    exit()

x1 = path.index(now)
x2 = len(path)-1
x3 = (k-x1)%(x2-x1)
print(path[x1+x3])



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

now=1
flg = 0
path = [1]
pathcheck ={1}
for i in range(k):
    now = a[now-1]
    if now in pathcheck:
        flg = -1
        path.append(now)
        break
    path.append(now)
    pathcheck.add(now)


if flg == 0:
    print(now)
    exit()

x1 = path.index(now)
x2 = len(path)-1
x3 = (k-x1)%(x2-x1)
print(path[x1+x3])

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

flg = 0
now=1
path=[1]
while flg < k:
    flg = flg+1
    now = a[now-1]
    if now in path:
        flg=k+1
    path.append(now)

if flg == k:
    print(now)
    exit()

x1 = path.index(now)
x2 = len(path)-1
x3 = (k-x1)%(x2-x1)
print(path[x1+x3])



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

now=1
flg = 0
path = [1]
pathcheck ={1}
for i in range(k):
    now = a[now-1]
    if now in pathcheck:
        flg = -1
        path.append(now)
        break
    path.append(now)
    pathcheck.add(now)


if flg == 0:
    print(now)
    exit()

x1 = path.index(now)
x2 = len(path)-1
x3 = (k-x1)%(x2-x1)
print(path[x1+x3])