CodeEff/ECCO huggingface dataset:
# Original solution
N, K = list(map(int, input().split()))
A = list([int(x) - 1 for x in input().split()])

v = [[-1]*N for i in range(61)]
v[0] = A[:]
now = 0
for i in range(60):
    for j in range(N):
        v[i+1][j] = v[i][v[i][j]]
    if K>>i & 1:
        now = v[i][now]
print((now + 1))

# Optimized solution
N, K = list(map(int, input().split()))
A = list([int(x) - 1 for x in input().split()])

v = [A[:]]
now = 0
for i in range(60):
    tmp = v[-1]
    v.append([tmp[x] for x in tmp])
    if K>>i & 1:
        now = v[i][now]
print((now + 1))
# Original solution
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
A=[-1]+A
still=[1]
before=1
rS=-1
root=[1]
while True:
  dest=A[before]
  if dest in still:
    rS=dest
    break
  else:
    still.append(dest)
    root.append(dest)
    before=dest
#print(root,rS)
num=0
for i in root:
  if i==rS:
    break
  num+=1
#print(num)
if K<=num:
  print((root[K]))
else:
  K-=num
  root2=root[num:]
  print((root2[K%len(root2)]))
  

# Optimized solution
N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
A=[-1]+A
still=[0]*(N+1)
still[1]=1
before=1
rS=-1
root=[1]
while True:
  dest=A[before]
  if still[dest]==1:
    rS=dest
    break
  else:
    still[dest]=1
    root.append(dest)
    before=dest
#print(root,rS)
num=0
for i in root:
  if i==rS:
    break
  num+=1
#print(num)
if K<=num:
  print((root[K]))
else:
  K-=num
  root2=root[num:]
  print((root2[K%len(root2)]))
# Original solution
N,K = list(map(int, input().split()))
A = [int(x)-1 for x in map(int, input().split())]

l = []
place = 0
while True:
    if K==0:
        print((place+1))
        exit()
    l.append(place)
    place = A[place]
    K -= 1
    if place in l:
        ind = l.index(place)
        count = len(l) - ind
        print((l[ind + K%count]+1))
        exit()

# Optimized solution
N,K = list(map(int, input().split()))
A = [int(x)-1 for x in map(int, input().split())]
flag = [False]*N
l = []
place = 0
while True:
    if K==0:
        print((place+1))
        exit()
    l.append(place)
    flag[place]=True
    place = A[place]
    K -= 1
    if flag[place]:
        ind = l.index(place)
        count = len(l) - ind
        print((l[ind + K%count]+1))
        exit()
# Original solution
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,K = list(map(int, readline().split()))
    A = [int(i) for i in readline().split()]

    d = [0] * (N+1)
    d[1] = 1
    now = 1
    next_ = A[0]
    c = [0] * (N+1)
    cnt = 0
    while d[next_] == 0:
        d[next_] = d[now] + 1
        now = next_
        next_ = A[next_-1]
        cnt += 1
        c[now] = cnt

    s = c[next_]
    loop = cnt - s

    if K <= s:
        ans = c[1:].index(K) + 1
    else:
        n = (K - s) % (loop + 1)
        ans = c[1:].index(s + n) + 1
    
    print(ans)


if __name__ == "__main__":
    main()


# Optimized solution
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,K = list(map(int, readline().split()))
    A = [int(i) - 1 for i in readline().split()]

    p = 0
    route = []
    seen = set()
    while True:
        route.append(p)
        seen.add(p)
        p = A[p]
        if p in seen:
            break
    
    loop_start = route.index(p)
    loop_len = len(route) - loop_start

    if K <= loop_start:
        ans = route[K] + 1
    else:
        r = (K - loop_start) % loop_len
        ans = route[loop_start + r] + 1
    
    print(ans)


if __name__ == "__main__":
    main()
# Original solution
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

path = [1]
current_pos = 1
detect_loop = False

while not detect_loop:
    current_pos = A[current_pos - 1]
    if current_pos in path:
        detect_loop = True
    path.append(current_pos)

loop = path[(idx := path.index(current_pos)):-1]
straight = path[:idx]

if K < len(straight):
    print((straight[K]))
else:
    print((loop[(K - len(straight)) % len(loop)]))



# Optimized solution
N, K = [int(x) for x in input().split()]
A = [int(x) for x in input().split()]

path = [1]
checked = [False] * N
detect_loop = False

current_pos = 1
while not detect_loop:
    current_pos = A[current_pos - 1]

    if checked[current_pos - 1]:
        detect_loop = True

    path.append(current_pos)
    checked[current_pos - 1] = True

loop = path[(idx := path.index(current_pos)):-1]
straight = path[:idx]

if K < len(straight):
    print((straight[K]))
else:
    print((loop[(K - len(straight)) % len(loop)]))
# Original solution
import sys

readline = sys.stdin.readline
n, k = list(map(int, readline().split()))
A = [i - 1 for i in map(int, readline().split())]

m = 64
d = [A]
pre = A
for i in range(m):
    current = [pre[pre[j]] for j in range(n)]
    d.append(current)
    pre = current

route = 0
for i in range(m-1, -1, -1):
    if k >= (x := 1 << i):
        route = d[i][route]
        k -= x
print((route+1))


# Optimized solution
import sys

readline = sys.stdin.readline
n, k = list(map(int, readline().split()))
A = [i - 1 for i in map(int, readline().split())]

m = 60
d = [A]
pre = A
for i in range(m):
    current = [pre[pre[j]] for j in range(n)]
    d.append(current)
    pre = current

route = 0
for i in range(m-1, -1, -1):
    if k >= (x := 1 << i):
        route = d[i][route]
        k -= x
print((route+1))
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int,input().split()))

A.insert(0,-1)
root = [1]
next = A[1]
rf = 0

for _ in range(K):
    if next in root:
        rf = root.index(next)
        root = root[rf:]
        break
    root.append(next)
    next = A[next]

print((root[(K - rf) % len(root)]))


# Optimized solution
N, K = list(map(int, input().split()))
A = list(map(int,input().split()))

A.insert(0,-1)
root = [1]

for _ in range(N-1):
    root.append(A[root[-1]])

if K > N:
    start = root.index(root[-1])
    index = (K - start) % (len(root) - start - 1) + start
    ans = root[index]
else:
    ans = root[K]

print(ans)
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
r = [None] * N
i = 0
cur = 0
m = None
while True:
    if r[cur] is not None:
        m = i - r[cur]
        K -= ((K-i)//m)*m
    r[cur] = i
    i += 1
    if i == K:
        print((A[cur]))
        exit()
    cur = A[cur] - 1

# Optimized solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
r = [None] * N
i = 0
cur = 0
m = None
while True:
    if m is None and r[cur] is not None:
        m = i - r[cur]
        K = i + (K-i)%m
    else:
        r[cur] = i
    if i == K:
        print((cur+1))
        exit()
    i += 1
    cur = A[cur] - 1
# Original solution
from collections import deque
import sys

n, k = list(map(int, input().split()))
a = list([int(x)-1 for x in input().split()])

visited = deque()
i = 0
cnt = 0
while True:
    if cnt == k:
        print((i+1))
        sys.exit()
    if i in visited:
        break
    visited.append(i)
    i = a[i]
    cnt += 1

si = visited.index(i)
loop = list(visited)[si:]
n_loop = len(loop)
left_k = k - cnt
print((loop[left_k % n_loop] + 1))

# Optimized solution
import sys

n, k = list(map(int, input().split()))
a = list([int(x)-1 for x in input().split()])

is_visited = [0] * n
visited = list()
i = 0
cnt = 0
while True:
    if cnt == k:
        print((i+1))
        sys.exit()
    if is_visited[i]:
        break
    is_visited[i] = 1
    visited.append(i)
    i = a[i]
    cnt += 1

si = visited.index(i)
loop = visited[si:]
n_loop = len(loop)
left_k = k - cnt
print((loop[left_k % n_loop] + 1))
# Original solution
a, b = list(map(int, input().split()))
c = list(map(int, input().split()))
itta = []
mati = 1
i = 0
while True:
    if mati in itta:
        saisyo = mati
        break
    else:
        itta.append(mati)
        mati = c[mati-1]
        i += 1
risuto = []
while True:
    if mati in risuto:
        break
    else:
        risuto.append(mati)
        mati = c[mati-1]
if b <= i-1:
    print((itta[b]))
else:
    print((risuto[(b-i) % len(risuto)]))

# Optimized solution
a, b = list(map(int, input().split()))
c = list(map(int, input().split()))
itta2 = set([])
mati = 1
i = 0
itta = []
while True:
    if mati in itta2:
        saisyo = mati
        break
    else:
        itta2.add(mati)
        itta.append(mati)
        mati = c[mati-1]
        i += 1
risuto2 = set([])
risuto = []

while True:
    if mati in risuto2:
        break
    else:
        risuto2.add(mati)
        risuto.append(mati)
        mati = c[mati-1]
if b <= i-1:
    print((itta[b]))
else:
    print((risuto[(b-i) % len(risuto)]))
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
 
t = 0
now = 1
footprint = [1]
 

while t < K:
  if A[now-1] not in footprint:
    footprint.append(A[now-1])
    now = A[now-1]
    t += 1
  else:
    s = footprint.index(A[now-1])
    l = t - s + 1
    e = (K-s) % l
    now = footprint[s+e]
    break
    
print(now)

# Optimized solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
 
t = 0
now = 1
footprint = [1]
past = [0]*N
past[0] = 1

while t < K:
  if past[A[now-1]-1] == 0:
    now = A[now-1]
    footprint.append(now)
    past[now-1]=1
    t += 1
  else:
    s = footprint.index(A[now-1])
    l = t - s + 1
    e = (K-s) % l
    now = footprint[s+e]
    break
    
print(now)
# Original solution
(N,K) = list(map(int,input().split()))
A = list(map(int,input().split()))
route = [1]
past = 1
for i in range(K):
    past = A[past-1]
    if past in route:
        loop = (route.index(past),i+1)
        flag = 0
        break
    else:
        flag = 1
        route.append(past)
if flag == 1:
    print((route[-1]))
else:
    print((route[loop[0]+(K-loop[0])%(loop[1]-loop[0])]))


# Optimized solution
(N,K) = list(map(int,input().split()))
A = list(map(int,input().split()))
route = [1]
App = [0]*N
past = 1
for i in range(K):
    past = A[past-1]
    if App[past-1]==1:
        loop = (route.index(past),i+1)
        flag = 0
        break
    else:
        App[past-1] = 1
        flag = 1
        route.append(past)
if flag == 1:
    print((route[-1]))
else:
    print((route[loop[0]+(K-loop[0])%(loop[1]-loop[0])]))
# Original solution
N, K = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))
B = [1]
i = 1
n = 0
l = 1
while 1:
  i = A[i]
  if i not in B:
    B.append(i)
    l = l + 1
    if l == K + 1:
      print(i)
      break
  else:
    n = B.index(i)
    print((B[n + (K-n) % (l-n)]))
    break

# Optimized solution
N, K = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))
B = [-1 for i in range(N+1)]
B[1] = 0
n = 1
m = 0
while 1:
  n = A[n]
  m += 1
  if m == K:
    print(n)
    break
  if B[n] == -1:
    B[n] = m
  else:
    a = (K - m) % (m - B[n])
    for i in range(a):
      n = A[n]
    print(n)
    break
# Original solution
n,k = list(map(int,input().split()))

dic = {}
for key, a in zip(list(range(1, n+1)), list(map(int,input().split()))):
    dic[key] = a
 
keynum = 0
log = [1]
next = dic[1]
log.append(next)
k -= 1
while k:
    next = dic[next]
    if next in log:
        keynum = log.index(next)
        k -= 1
        break
    log.append(next)
    k -= 1
looplen = len(log[keynum:])
if k < len(log[keynum:]):
    print((log[-1]))
else:
    res = k%looplen
    print((log[keynum+res]))

# Optimized solution
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
dic = {}
for key, a in zip(list(range(1, n+1)), a):
    dic[key] = a
 
log = [-1]*(n+1)
next = dic[1]
step = 1
log[next] = step
k -= 1
while k:
    next = dic[next]
    step += 1
    k -= 1
    if log[next] != -1:
        k %= log[next] - step
    else:
        log[next] = step
print(next)
# Original solution
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
dic = {}
for key, a in zip(list(range(1, n+1)), a):
    dic[key] = a
 
log = [-1]*(n+1)
next = dic[1]
step = 1
log[next] = step
k -= 1
while k:
    next = dic[next]
    step += 1
    k -= 1
    if log[next] != -1:
        k %= log[next] - step
    else:
        log[next] = step
print(next)

# Optimized solution
n,k = list(map(int,input().split()))

a = [0]
a.extend(list(map(int,input().split())))
l = [None]*(n+1)

now = 1
step = 0
l[now] = 0
while k:
    now = a[now]
    step += 1
    k -= 1
    if l[now] is not None:
        looplen = (step - l[now])
        k = k%looplen
    else:
        l[now] = step
print(now)
# Original solution
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

ord_ = [-1] * (n + 1)
s = []
v = 1
while ord_[v] == -1:
    ord_[v] = len(s)
    s.append(v)
    v = a[v-1]
c = len(s) - ord_[v]
l = ord_[v]

if k < l:
    print((s[k]))
else:
    k -= l
    k %= c
    print((s[l+k]))



# Optimized solution
#!/usr/bin/env python3
import collections
import itertools as it
import math
#import numpy as np
 
#  = input()
#  = int(input())
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
#  = [int(input()) for i in range(N)]
#
# c = collections.Counter()

ord_ = [-1] * (n + 1) # 何回目に訪れたか
s = []
current = 0
while ord_[current] == -1:
    ord_[current] = len(s)
    s.append(current)
    current = a[current] - 1
c = len(s) - ord_[current]
l = ord_[current]

if k < l:
    print((s[k] + 1))
else:
    k -= l
    k %= c
    print((s[l+k] + 1))
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
history = []

pos = 0
cnt = 0
while pos not in history and cnt < k:
  history.append(pos)
  pos = a[pos] - 1
  cnt += 1

if cnt == k:
  print((pos + 1))
else:
  cnt_before = history.index(pos)
  print((history[cnt_before + (k - cnt_before) % (cnt - cnt_before)] + 1))

# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
history = []
mark = set()

pos = 0
cnt = 0
while pos not in mark and cnt < k:
  history.append(pos)
  mark.add(pos)
  pos = a[pos] - 1
  cnt += 1

if cnt == k:
  print((pos + 1))
else:
  cnt_before = history.index(pos)
  print((history[cnt_before + (k - cnt_before) % (cnt - cnt_before)] + 1))
# Original solution

def main():
    N, K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    A = [0] + A

    seen = {}
    cnt = 0
    dst = 1
    while K:
        if dst in seen:
            cycle = cnt - seen[dst]
            K %= cycle
            seen = {}
        else:
            seen[dst] = cnt

        dst = A[dst]
        cnt += 1
        K -= 1

    print(dst)


if __name__ == "__main__":
    main()


# Optimized solution
def main():
    N, K = list(map(int,input().split()))
    A = list(map(int,input().split()))
    A = [0] + A

    seen = {}
    find_cnt = {}
    cnt = 0
    dst = 1
    while K:
        if dst in seen:
            cycle = cnt - seen[dst]
            K %= cycle
            print((find_cnt[seen[dst]+K]))
            return

        else:
            seen[dst] = cnt
            find_cnt[cnt] = dst

        dst = A[dst]
        cnt += 1
        K -= 1

    print(dst)


if __name__ == "__main__":
    main()
# Original solution
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))

root = [1]

for i in range(n):
    t = a[root[i] - 1]
    root.append(t)
    if (t in root[:-1]):
        break
x =  root.index(root[-1])
bef = root[0:x]
#print(bef)
loop = root[x:-1]
#print(loop)
#print(root)

if (k < len(bef)):
    print((bef[k]))
else:
    p = ((k - len(bef)) % len(loop))
    #print(p)
    print((loop[p]))

# Optimized solution
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))

root = [1]

for i in range(n):
    t = a[root[i]-1]
    if (t == 0):
        break
    a[root[i]-1] = 0
    root.append(t)
x =  root.index(root[-1])
bef = root[0:x]
#print(bef)
loop = root[x:-1]
#print(loop)
#print(root)

if (k < len(bef)):
    print((bef[k]))
else:
    p = ((k - len(bef)) % len(loop))
    #print(p)
    print((loop[p]))
# Original solution
n,k=list(map(int,input().split()))
teleport=list(map(int,input().split()))
double_counter=set()
# mojiretu="1"
mojiretu=["1"]
index=1
double_counter.add(index)
flag=False
for i in range(k):
    tmp=teleport[index-1]
    if tmp in double_counter:
        flag=True
        break
    else:
        double_counter.add(tmp)
        # mojiretu+=str(tmp)
        mojiretu.append(str(tmp))
        index=tmp
else:
    print(tmp)

if flag:
    # index=mojiretu.find(str(tmp))
    # roop_str=mojiretu[index:]
    # length=k%len(roop_str)-len(mojiretu[:index])%len(roop_str)
    # print(roop_str[length])

    Li = mojiretu.index(str(tmp))
    Ri = len(mojiretu)
    idx = Li + (k - Li) % (Ri - Li)
    print((mojiretu[idx]))


# Optimized solution
n,k=list(map(int,input().split()))
teleport=list(map(int,input().split()))
double_counter=set()
# mojiretu="1"
mojiretu=["1"]
index=1
double_counter.add(index)
flag=False
for i in range(k):
    tmp=teleport[index-1]
    if tmp in double_counter:
        flag=True
        break
    else:
        double_counter.add(tmp)
        # mojiretu+=str(tmp)
        mojiretu.append(str(tmp))
        index=tmp
else:
    print(tmp)

if flag:
    # index=mojiretu.find(str(tmp))
    # roop_str=mojiretu[index:]
    # length=k%len(roop_str)-len(mojiretu[:index])%len(roop_str)
    # print(roop_str[length])

    index = mojiretu.index(str(tmp))
    roop_str=mojiretu[index:]
    length=k%len(roop_str)-len(mojiretu[:index])%len(roop_str)
    print((roop_str[length]))
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
l = [1]
lnew = [1]
for i in range(n):
  lnew.append(a[l[i]-1])
  if lnew[-1] in l == True:
    break
  else:
    l.append(lnew[-1])

del l[-1]
lindex = l.index(l[-1])
del l[-1]
r = len(l) - lindex
rlist = l[lindex:]

if k >= lindex:
  kmod = (k - lindex) % r
  ans = rlist[kmod]
else:
  ans = l[k]
  
print(ans)

# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
l = [1]
b = [1] + [0] * (n-1)
for i in range(n):
  b[a[l[i]-1]-1] += 1
  if b[a[l[i]-1]-1] == 2:
    break
  else:
    l.append(a[l[i]-1])

lindex = l.index(a[l[i]-1])
r = len(l) - lindex
rlist = l[lindex:]

if k >= lindex:
  kmod = (k - lindex) % r
  ans = rlist[kmod]
else:
  ans = l[k]
  
print(ans)
# Original solution
if __name__=="__main__":
    N, K = list(map(int, input().split(' ')))
    _town_list = input().split(' ')
    town_list = [int(n) for n in _town_list]

    next_town = town_list[0]
    visited_town = [1]
    visited_town.append(next_town)
    counter = 1

    while True:
        counter += 1
        next_town = town_list[next_town-1]
        if counter == K:
            print(next_town)
            break
        if next_town in visited_town:
            repeated_town_idx = visited_town.index(next_town)
            loop_num = counter - repeated_town_idx
            print((visited_town[(K-repeated_town_idx)%loop_num + repeated_town_idx]))
            break
        visited_town.append(next_town)

# Optimized solution
if __name__=="__main__":
    N, K = list(map(int, input().split(' ')))
    _town_list = input().split(' ')
    town_list = [int(n) for n in _town_list]

    next_town = town_list[0]
    visited_town = set()
    visited_town.add(1)
    visited_town.add(next_town)
    lst_visited_town = [1]
    lst_visited_town.append(next_town)
    counter = 1

    while True:
        counter += 1
        next_town = town_list[next_town-1]
        if counter == K:
            print(next_town)
            break
        if next_town in visited_town:
            repeated_town_idx = lst_visited_town.index(next_town)
            loop_num = counter - repeated_town_idx
            print((lst_visited_town[(K-repeated_town_idx)%loop_num + repeated_town_idx]))
            break
        lst_visited_town.append(next_town)
        visited_town.add(next_town)
# Original solution
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N,K = LI()
    A = [0] + LI()

    his = [0] * (N+1)
    s = 1
    cnt = 1
    his[1] = 1
    while his[A[s]] == 0:
        s = A[s]
        cnt += 1
        his[s] = cnt


    if K >= cnt:
        s = A[s]
        cnt -= his[s] - 1

        k = (K - his[s] + 1) % cnt
    else:
        k = K
        s = 1
    for i in range(k):
        s = A[s]
    print(s)



if __name__ == '__main__':
    main()

# Optimized solution
import sys,queue,math,copy,itertools,bisect,collections,heapq

def main():
    sys.setrecursionlimit(10**7)
    LI = lambda : [int(x) for x in sys.stdin.readline().split()]
    NI = lambda : int(sys.stdin.readline())

    N,K = LI()
    A = [0] + LI()

    his = [0] * (N+1)
    s = 1
    cnt = K

    while cnt > 0:
        his[s] = cnt
        s = A[s]
        cnt -= 1
        if his[s] > cnt:
            cnt = cnt % (his[s]-cnt)
    print(s)

if __name__ == '__main__':
    main()
# Original solution
n,k=list(map(int,input().split()))
loop_=[1]
lst=list(map(int,input().split()))
 
for i in range(k):
    num=lst[loop_[-1]-1]
    if num in loop_:
        tar=num
        break
    else:
        loop_.append(num)
    if i==k-1:
        print((loop_[k]))
        exit() 
        
loop__=loop_[loop_.index(tar):]
 
if k<=len(loop_):
    print((loop_[k]))
else:
    num=k+1-len(loop_)
    print((loop__[num%len(loop__)-1]))

# Optimized solution
n,k=list(map(int,input().split()))
loop_=[1]
l_set=set()
lst=list(map(int,input().split()))

tar=None
for i in range(k):
    num=lst[loop_[-1]-1]
    if num in l_set:
        tar=num
        break
    else:
        loop_.append(num)
        l_set.add(num)

if tar==None:
    print((loop_[k]))
    exit()    
loop__=loop_[loop_.index(tar):]

num=k+1-len(loop_)
try:
  print((loop__[num%len(loop__)-1]))
except:
  print((1))
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
i = 0
his = []

if K >= N:
  for j in range(N):
    i = A[i]-1
    his.append(i)
    K -= 1

    for k in range(1, j):
      if his[j] == his[j-k]:
        K = K % k
        break

while K > 0:
  i = A[i]-1
  K -= 1

print((i+1))

# Optimized solution
N, K = list(map(int, input().split()))
A = [int(x) for x in input().split()]

when = [-1 for _ in range(N+1)]
new = 1
i = 0

while when[new] == -1:
    when[new] = i
    new = A[new - 1]
    i += 1

line = when[new]
roop = i - when[new]

if K > line:
    K = (K - line) % roop
    for j in range(N+1):
        when[j] -= line
    
for j in range(N+1):
    if when[j] == K:
        print(j)
        break
# Original solution
N, K = list(map(int, input().split()))
A = [int(i) for i in input().split()]

visit_time = [None] * N
now = 0
visit_time[now] = 0
loop_start_city = None
loop_last_city = None
loop_first = None
loop_second = None
for i in range(1, 2 * 10 ** 5 + 1):
    last = now
    now = A[now]-1
    if visit_time[now] is not None:
        loop_start_city = now
        loop_last_city = last
        loop_first = visit_time[now]
        loop_second = i
        break
    else:
        visit_time[now] = i
if loop_start_city is not None and K > loop_first:
    K += 1
    K -= loop_first
    K %= (loop_second - loop_first)
    now = last
else:
    now = 0
for i in range(K):
    now = A[now]-1
print((now+1))


# Optimized solution
N, K = list(map(int, input().split()))
A = [int(a)-1 for a in input().split()]

order = [-1] * N
s = []
now = 0
c = 0
a = None
b = None
while True:
    order[now] = c
    s.append(now)
    now = A[now]
    c += 1
    if order[now] >= 0:
        a = c - order[now]
        b = order[now]
        break
if K <= b:
    print((s[K] + 1))
else:
    K -= b
    K %= a
    print((s[K + b] + 1))