CodeEff/ECCO huggingface dataset:
# Original solution
from collections import deque
import sys

def main():
    input = sys.stdin.readline
    n,k = list(map(int,input().split()))

    a = [int(x) for x in input().split()]

    #ループを探す？

    checked_list = [1]
    que = deque([a[0]])

    counter = 0
    q_append = que.append
    c_append = checked_list.append

    while True:
        counter += 1
        x = que.popleft()
        if counter == k:
            print(x)
            exit()
        if x in set(checked_list):
            startflg = checked_list.index(x)
            loop_length = counter - startflg
            loop_list = checked_list[startflg:counter]
            amari = (k-startflg) % loop_length
            print((loop_list[amari]))
            exit()
        else:
            q_append(a[x-1])
            c_append(x)

if __name__ == '__main__':
    main()

# Optimized solution
from collections import deque
import sys

def main():
    input = sys.stdin.readline
    n,k = list(map(int,input().split()))

    a = [int(x) for x in input().split()]

    #ループを探す？

    checked_dict = {1:0}
    que = deque([a[0]])

    counter = 0


    while True:
        counter += 1
        x = que.popleft()
        if counter == k:
            print(x)
            exit()
        if x in checked_dict:
            startflg = checked_dict[x]
            loop_length = counter - startflg

            inverse_dict = {v:k for k,v in list(checked_dict.items())}

            loop_list = [inverse_dict[i] for i in range(startflg,startflg+loop_length)]
            amari = (k-startflg) % loop_length
            print((loop_list[amari]))
            exit()
        else:
            que.append(a[x-1])
            checked_dict[x] = counter

if __name__ == '__main__':
    main()
# Original solution
n,k = list(map(int, input().split()))
a = [0] + list(map(int, input().split()))
r = [1]
k += 1
now = 1
for i in range(n):
   now = a[now]
   if now in r: break
   r.append(now)
   if len(r) == k:
     print(now)
     exit()
I = r.index(now)
if I != 0: 
  k -= I
  r = r[I:]
print((r[-1] if k%len(r)==0 else r[k%len(r)-1]))

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

now = 1
check = [-1]*(n+1)

for i in range(k):
  if check[now] == -1:
    check[now] = i
    now = a[now]
  else:
    loop = i - check[now]
    afterloop = (k-(i-loop))%loop
    print((check.index((i-loop) + afterloop)))
    exit()
print(now)
# Original solution
import sys
n,k = list(map(int,input().split()))
ls = list(map(int,input().split()))
def sub(k,s):
    return k-s
p = [1]
i = 0
a = 0
t = 0
ans1 = 0
ans2 = 0
e = 3
while i<k-1:
    if i ==0:
        a = ls[i]
        p.append(a)
        if len(p) != len(list(set(p))):
            q = [p[-1]]*(len(p))
            p.pop()
            new = list(map(sub,p,q))
            t = new.index(0)
            ans1 = len(p[:t])
            ans2 = len(p[t:])
            print((p[((k+1-ans1)%ans2)-1]))
            sys.exit()
        b = ls[a-1]
        p.append(b)
        if len(p) != len(list(set(p))):
            q = [p[-1]]*(len(p))
            p.pop()
            new = list(map(sub,p,q))
            t = new.index(0)
            ans1 = len(p[:t])
            ans2 = len(p[t:])
            print((p[((k+1-ans1)%ans2)-1]))
            sys.exit()
        i += 1
    else:
        a = b
        b = ls[a-1]
        p.append(b)
        e += 1
        f = len(list(set(p)))
        if e != f:
            q = [p[-1]]*(e)
            p.pop()
            new = list(map(sub,p,q))
            t = new.index(0)
            ans1 = len(p[:t])
            ans2 = e-1 - ans1
            ansl = p[t:]
            print((ansl[((k+1-ans1)%ans2)-1]))
            sys.exit()
        i += 1
print(b)




# Optimized solution
n,k = list(map(int,input().split()))
ls = list(map(int,input().split()))
fi = [-1]*(n+1)
fi[1] = 0
a = 0
aa = 0
for i in range(k):
    if fi[ls[a]] == -1:
        fi[ls[a]] = i + 1
        aa = a
        a = ls[a] - 1
    else:
        ind = fi[ls[a]]
        t = (k - ind) % (max(fi) + 1 - ind)
        t += ind
        print((fi.index(t)))
        break
else:
    print((ls[aa]))
# Original solution
n, k = [int(x) for x in input().strip().split()]
a = [int(x) for x in input().strip().split()]
assert len(a) == n
a = [0] + a
current = 1
way = [1]
for i in range(k):
  current = a[current]
  if current in way:
    li = way.index(current)
    loop = way[li:]
    print((loop[(k - li) % len(loop)]))
    break
  else:
    way.append(current)
else:
  print(current)


# Optimized solution
n, k = [int(x) for x in input().split()]
a = [int(x)-1 for x in input().split()]
assert len(a) == n
current = 0
visited = [-1] * n
visited[0] = 0
for i in range(1, k):
  current = a[current]
  if visited[current] == -1:
    visited[current] = i
  else:
    pre = visited[current]
    count = (k - pre) % (i - pre) + pre
    print((visited.index(count)+1))
    break
else:
  print((a[current]+1))
# Original solution
N,K = list(map(int,input().split()))
A = [0] + [int(i) for i in input().split()]

route = [1]
start = 1
cnt = 0
while True:
  if cnt == K:
    print((route[-1]))
    exit()
  elif A[start] in route:
    index = route.index(A[start])
    loop = len(route) - index
    break
  else:
    route.append(A[start])
    start = A[start]
    cnt += 1

K -= index
K = K % loop
print((route[index:][K]))

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

route = [1]
route_set = set()
start = 1
cnt = 0
while True:
  if cnt == K:
    print((route[-1]))
    exit()
  elif A[start] in route_set:
    index = route.index(A[start])
    loop = len(route) - index
    break
  else:
    route.append(A[start])
    route_set.add(A[start])
    start = A[start]
    cnt += 1

K -= index
K = K % loop
print((route[index:][K]))
# Original solution
N, K = list(map(int, input().split()))
A = input().split()
A = [int(a) for a in A]
S = []
a = 1
number = 0
for _ in range(N + 1):
    b = A[a - 1]
    if b in S:
        c = S.index(b)
        break
    number += 1
    S.append(b)
    a = b
T = S[c:number]
if K <= N:
    print((S[K - 1]))
else:
    z = K - c - 1
    y = z % (number - c)
    print((T[y]))


# Optimized solution
N, K = list(map(int, input().split()))
A = input().split()
A = [int(a) for a in A]
S = [1]
a = 1
number = 0
numbers=[-1 for _ in range(N)]
for _ in range(N + 1):
    b = A[a - 1]
    if numbers[b-1] != -1:
      c=numbers[b-1]
      break
    numbers[b-1]=number
    number += 1
    S.append(b)
    a = b
T = S[c+1:number+1]
if K <= number:
  print((S[K ]))
else:
  z = K - c-1
  y = z % (number - c)
  print((T[y]))
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
g = dict()

for i, v in enumerate(a):
    g[i+1] = v

def find_num(target):
    path = 1
    target_ = g[target]
    while target_ != target:
        target_ = g[target_]
        path += 1
    return path

target = 1
visited = []
flag = False
for i in range(k):
    target = g[target]
    if target not in visited:
        visited.append(target)
    else:
        p = find_num(target)
        flag = True
        break
if flag:
    for _ in range((k-1-i)%p):
        target = g[target]
    print(target)
else:
    print(target)

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

for i, v in enumerate(a):
    g[i+1] = v

def find_num(target):
    path = 1
    target_ = g[target]
    while target_ != target:
        target_ = g[target_]
        path += 1
    return path

target = 1
visited = dict()
flag = False
for i in range(k):
    target = g[target]
    if target not in visited:
        visited[target] = True
    else:
        p = find_num(target)
        flag = True
        break
if flag:
    for _ in range((k-1-i)%p):
        target = g[target]
    print(target)
else:
    print(target)
# Original solution
n, k = list(map(int, input().split()))
tele = list(map(int, input().split()))
loc = 1
act = [[0]*n for i in range(n)]
count = 1
log = []
log.append(loc)
while True:
  newloc=tele[loc-1]
  log.append(newloc)
  #print(newloc)
  if act[loc-1][newloc-1] == 0:
    act[loc-1][newloc-1] =count
    act[newloc-1][loc-1] =count
  else:
    loop=count-act[loc-1][newloc-1]
    loopstart=act[loc-1][newloc-1]
    break
  count+=1
  loc=newloc

if k <= loopstart:
  ans=log[k]
else:
  num = (k-(loopstart-1)) % loop 
  ans=log[loopstart-1+num]
#print(loop)
#print(loopstart)
#print(count)
#print(act)
#print(log)
print(ans)
    
  

# Optimized solution
n, k = list(map(int, input().split()))
tele = list(map(int, input().split()))
loc = 1
act = [-1]*n
act[0]=0
count = 1
log = []
log.append(loc)
flg = True
while True:
  newloc=tele[loc-1]
  if count ==k:
    print(newloc)
    flg = False
  log.append(newloc)
  #print(newloc)
  if act[newloc-1] == -1:
    act[newloc-1] =count
  else:
    loop=count-act[newloc-1]
    loopstart=act[newloc-1]
    break
  count+=1
  loc=newloc

  

if flg:
  num = (k-loopstart) % loop 
  ans=log[loopstart+num]
  print(ans)

#print(loopstart)
#print(log)
#print(log[loopstart])
#print(num)
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
l = [1]
for i in range(n):
    if a[l[i] - 1] in l:
        res = l[:l.index(a[l[i] - 1])]
        cyc = l[l.index(a[l[i] - 1]):]
        break
    else:
        l += [a[l[i] - 1]]
print((cyc[(k - len(res)) % len(cyc)] if k > len(res) - 1 else res[k]))

# Optimized solution
n, k = list(map(int, input().split()))
a = list([int(x) - 1 for x in input().split()])
visited = [-1 for _ in range(n)]
visited[0] = 0
l = [0]
for i in range(k):
    nex = a[l[i]]
    if visited[nex] != -1:
        res = visited[nex]
        cyc = i + 1 - visited[nex]
        break
    else:
        l += [nex]
        visited[nex] = i + 1
else:
    res = k + 1
print((l[res + (k - res) % cyc] + 1 if k > res else l[k] + 1))
# Original solution
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
A = LIST()

a = [1]
r = -1
loc = 1


for i in range(N):
	loc = A[loc-1]
	#print(loc)
	if not loc in a:
		a.append(loc)
		#print(a)
	else:
		r = i+1
		loop_start = loc
		break

#print(a)
#print(r)
#print(loop_start)

for i in range(N):
	if a[i] == loop_start:
		l = i
		break

first = a[:l]
loop = a[l:]

#print(l, r)
#print(first)
#print(loop)


K += 1

if K <= len(first):
	print((a[K-1]))
else:
	K -= len(first)
	K %= len(loop)
	print((loop[K-1]))

# Optimized solution
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, gcd, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(eval(input()))
def MAP(): return list(map(int, input().split()))
def LIST(): return list(map(int, input().split()))
def ZIP(n): return list(zip(*(MAP() for _ in range(n))))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N, K = MAP()
A = LIST()

a = [1]
r = -1
loc = 1
b = [0]*(N+1)
b[1] = 1


for i in range(N):
	loc = A[loc-1]
	#print(loc)
	if b[loc] == 0:
		a.append(loc)
		b[loc] = 1
		#print(a)
	else:
		r = i+1
		loop_start = loc
		break

#print(a)
#print(r)
#print(loop_start)

for i in range(N):
	if a[i] == loop_start:
		l = i
		break

first = a[:l]
loop = a[l:]

#print(l, r)
#print(first)
#print(loop)


K += 1

if K <= len(first):
	print((a[K-1]))
else:
	K -= len(first)
	K %= len(loop)
	print((loop[K-1]))
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

d = {}
for i in range(1, n + 1):
    d[i] = a[i - 1]

did = set()
route = [1]

now = 1
for i in range(k):
    now = d[now]
    route.append(now)
    if now in did:
        break
    did.add(now)

if k < 10 ** 6:#計算量的に間に合うので愚直に
    now = 1
    for i in range(k):
        now = d[now]

    print(now)

else:
    for i in range(len(route)):
        if route[i] == route[-1]:#routeには第二ループの始めがギリ入っている
            roop = route[i:-1]
            print((roop[(k - i) % len(roop)]))#k-iは残り移動階数
            exit()

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

d = {}
for i in range(1, n + 1):
    d[i] = a[i - 1]

did = set([1])
route = [1]

now = 1
for i in range(k):
    now = d[now]
    route.append(now)
    if now in did:
        break
    did.add(now)

if k < 10 ** 6:#計算量的に間に合うので愚直に
    now = 1
    for i in range(k):
        now = d[now]

    print(now)

else:
    for i in range(len(route)):
        if route[i] == route[-1]:
            roop = route[i:-1]
            print((roop[(k - i) % len(roop)]))
            exit()
# Original solution
import math
def fact(n):
    ans = 1
    for i in range(2, n+1):
        ans*= i
    return ans
def comb(n, c):
    return fact(n)//(fact(n-c)*c)

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
cnt=  0
i = 1
cycle = ['1']

for c in range(n):
    i = a[i-1]
    if(i in cycle):
        break
    else:
        cycle.append(i)

ind = cycle.index(i)
k-= ind
rcycle = cycle[ind:]
if(k <= 0):
    print((cycle[k+ind]))
else:
    now = (k+1)%len(rcycle)
    print((rcycle[now-1]))

# Optimized solution
import math
def fact(n):
    ans = 1
    for i in range(2, n+1):
        ans*= i
    return ans
def comb(n, c):
    return fact(n)//(fact(n-c)*c)
'''
n, k = map(int, input().split())
a = list(map(int, input().split()))
cnt=  0
i = 1
cycle = ['1']

for c in range(n):
    i = a[i-1]
    if(i in cycle):
        break
    else:
        cycle.append(i)

ind = cycle.index(i)
k-= ind
rcycle = cycle[ind:]
if(k <= 0):
    print(cycle[k+ind])
else:
    now = (k+1)%len(rcycle)
    print(rcycle[now-1])
'''
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))
already = ["1"]
set = {"1"}
now = 1
 
for i in range(n):
    now = str(a[int(now)-1])
    if now in set:
        break
    else:
        already.append(now)
        set.add(now)
 
 
ind = already.index(now)
k -= ind
cycle = already[ind:]
 
if k <= 0:
    print((already[k+ind]))
else:
    now = (k+1) % len(cycle)
    print((cycle[now-1]))
# Original solution
n,k= list(map(int, input().split()))
li= list(map(int, input().split()))
c=[1]
nex=1
first=0
flag=0
for i in range(k):
    nex=li[nex-1]
    if nex in c:
        first=c.index(nex)
        flag=1
        break
    c.append(nex)
if flag:
    k-=first
    k%=len(c)-first
    print((c[first+k]))
else:
    print((c[-1]))

# Optimized solution
n,k= list(map(int, input().split()))
li= list(map(int, input().split()))
d = [0 for i in range(n)]
c=[1]
nex=1
first=0
flag=0
for i in range(k):
    nex=li[nex-1]
    if d[nex-1]:
        first=c.index(nex)
        flag=1
        break
    d[nex-1]=1
    c.append(nex)
if flag:
    k-=first
    k%=len(c)-first
    print((c[first+k]))
else:
    print((c[-1]))
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = [0] + a
c = [1]

while c.count(c[-1]) == 1:
    c.append(a[c[-1]])

t = c.index(c[-1])
if k <= t:
    ans = c[k]
else:
    ans = c[t + ((k-t) % (len(c)-1-t))]

print(ans)

# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
a = [0] + a
c = [1]
x = True
y = [1, 1] + [0]*(n-1)

while x:
    c.append(a[c[-1]])
    y[c[-1]] += 1
    if y[c[-1]] == 2:
        x = False

t = c.index(c[-1])
if k <= t:
    ans = c[k]
else:
    ans = c[t + ((k-t) % (len(c)-1-t))]

print(ans)
# Original solution
from collections import deque
N, K= list(map(int, input().split()))
A = list(map(int, input().split()))


x = deque([1])
point = 1
count = 0
while True:
  next_point = A[point-1]
  if next_point in x :
    x.append(next_point)
    break
  x.append(next_point)
  point = next_point
  
f = x.index(next_point)

if K <=f:
    print((x[K]))
else :
    num = len(x) - f -1
    x = list(x)[f+1:]
    dic = {(n+1+f) %(num): i for n, i in enumerate(x)}
    print((dic[K%num]))

  

# Optimized solution
N, K= list(map(int, input().split()))
A = list(map(int, input().split()))
x = {1:0}
point = 1
count = 0
while True:
  next_point = A[point-1]
  count +=1
  if next_point in x :
    flag=next_point
    break
  x[next_point] =count
  point = next_point
  
#print(count, x[flag])
c = count - x[flag]
f = x[flag]
#print(c)
if K <f:
    print(([i for i in x if x[i] == K ][0]))
else :
    dic = {j-f: i for i,j in list(x.items())}
    print((dic[(K-f) % c]))
# Original solution
N, K = list(map(int,input().split()))
move_list = list(map(int,input().split()))
 
  
test = 1
find_f = {}
for i in range(N):
  find_f[i+1]=[]
 
find_f[1].append(0)
for i in range(K):
  test = move_list[test-1]
  find_f[test].append(i+1)
  if len(find_f[test]) == 2 and find_f[test][1]-find_f[test][0]<=100000:
    state ,f = test, find_f[test]
    break
try:
  K = K-f[0]
  f = f[1]-f[0]
  remain = K%f

  for i in range(remain):
    state = move_list[state-1]

  print(state)
except:
  print(test)
#state = 1

# Optimized solution
N, K = list(map(int,input().split()))
move_list = list(map(int,input().split()))
 
  
test = 1
find_f = {}
for i in range(N):
  find_f[i+1]=[]
 
find_f[1].append(0)
for i in range(K):
  test = move_list[test-1]
  find_f[test].append(i+1)
  if len(find_f[test]) == 2 and find_f[test][1]-find_f[test][0]<=1000000:
    state ,f = test, find_f[test]
    break
try:
  K = K-f[0]
  f = f[1]-f[0]
  remain = K%f
  for i in range(remain):
    state = move_list[state-1]
 
  print(state)
except:
  print(test)
#state = 1
# Original solution
n,k=[int(x) for x in input().split()]
p=[(int(x)-1) for x in input().split()]
a=[0]
i=0
while p[i] not in a:
  a.append(p[i])
  i=p[i]
l=a.index(p[i])
if k<=l: print((1+a[k]))  
else: print((1+a[l+(k-l)%(len(a)-l)]))

# Optimized solution
n,k=[int(x) for x in input().split()]
p=[(int(x)-1) for x in input().split()]
alp=[0 for _ in range(n)]
a=[0]
i=0
alp[0]=1
while alp[p[i]]==0:
  a.append(p[i])
  alp[p[i]]=1
  i=p[i]
l=a.index(p[i])
if k<=l: print((1+a[k]))
else: print((1+a[l+(k-l)%(len(a)-l)]))
# Original solution
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))

init = [1]
len_loop = -1

while len(init) <= k:
    nxt = a[init[-1]-1]
    if nxt in init:
        idx_nxt = init.index(nxt)
        len_init = idx_nxt
        len_loop = len(init) - idx_nxt
        break
    else:
        init.append(nxt)

if len_loop == -1:
    print((init[k]))
else:
    idx = (k-len_init)%len_loop
    print((init[len_init+idx]))

# Optimized solution
n, k = list(map(int, input().split()))
a = tuple([int(n) - 1 for n in input().split()])

visited = [0] * n
next_town = 0
order = []

while True:
    if visited[next_town]:
        break
    order.append(next_town)
    visited[next_town] = 1
    next_town = a[next_town]

first_loop = len(order)
offset = order.index(next_town)
second_loop = first_loop - offset

if k < first_loop:
    print((order[k] + 1))
else:
    print((order[offset + (k - first_loop) % second_loop] + 1))
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= 1
mod = -1
num = [0]
prev = 0
cnt = 0
# num.append(0)
while True:
    # print(num, cnt)
    if not a[prev] in num:
        num.append(a[prev])
        prev = a[prev]
    else:
        lpst = a[prev] 
        mod = cnt - num.index(a[prev]) + 1
        break
    cnt += 1

# print(mod, lpst)
now = 0
while k > 0:
    if now == lpst:
        k %= mod
    if k == 0:
        break
    now = a[now]
    k -= 1
    # print(now, k)


print((now+1))

# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
for i in range(n):
    a[i] -= 1
used = set()
num = [0]*n
used.add(0)
now = 0
cnt = 0
while True:
    cnt += 1
    if not a[now] in used:
        used.add(a[now])
        num[a[now]] = cnt
        now = a[now]
    else:
        lps = a[now]
        mod = cnt - num[a[now]]
        # k %= mod
        break
now = 0
# print(mod, lps, k, num)
while k:
    if now == lps:
        k %= mod
    if k == 0:
        break
    now = a[now]
    k -= 1

print((now+1))
# Original solution
def main():
    N, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    d = []
    d_set = set()
    s = 1
    for _ in range(N):
        if s in d_set:
            if K < len(d):
                return print(d[K])
            idx = d.index(s)
            K -= idx
            d = d[idx:]
            break
        d.append(s)
        d_set.add(s)
        s = A[s-1]

    # print(idx, d)
    K %= len(d)
    print(d[K])


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    N, K = (int(i) for i in input().split())
    A = [int(i) for i in input().split()]
    d = [-1]*(N+1)
    v = 1
    i = 0
    while d[v] == -1:
        d[v] = i
        v = A[v-1]
        i += 1
    c_length = i - d[v]  # 閉路長
    pre_c_length = d[v]
    if K < i:
        return print(d.index(K))
    else:
        K -= pre_c_length
        K %= c_length
        return print(d.index(pre_c_length+K))


if __name__ == '__main__':
    main()
# Original solution
N, K = list(map(int, input().split()))

A    = [int(i)-1 for i in input().split()]

visited_town = []
current_town = 0
loop_flg     = False
visited_town.append(current_town)
for i in range(K):
    current_town = A[current_town]
    if current_town in visited_town:
        visited_town.append(current_town)
        loop_flg = True
        break
    visited_town.append(current_town)


if loop_flg:
    loop_start = visited_town.index(current_town)
    loop_end   = len(visited_town) - 1
    loop_length = loop_end - loop_start
    last_index = (K-loop_start)%loop_length
    current_town = visited_town[loop_start+last_index]

print((current_town+1))

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

    visited_town = []
    current_town = 0
    loop_flg     = False
    visited_town.append(current_town)
    set_visted_town = set(visited_town)
    for i in range(K):
        current_town = A[current_town]
        if current_town in set_visted_town:
            visited_town.append(current_town)
            loop_flg = True
            break
        visited_town.append(current_town)
        set_visted_town.add(current_town)


    if loop_flg:
        loop_start = visited_town.index(current_town)
        loop_end   = len(visited_town) - 1
        loop_length = loop_end - loop_start
        last_index = (K-loop_start)%loop_length
        current_town = visited_town[loop_start+last_index]

    print((current_town+1))


if __name__ == '__main__':
    main()
# Original solution
N, K = list(map(int, input().split()))
*A, = list(map(int, input().split()))
A = [a-1 for a in A]

# Douling(ダブリング)
i = 1
to = [[a for a in A]]
while pow(2, i) < K:
    t = [to[i-1][to[i-1][j]] for j in range(N)]
    to.append(t)
    i += 1

i -= 1
ans = [i for i in range(N)]
while i >= 0:
    if K & (1 << i) > 0:
        for j in range(N):
            ans[j] = to[i][ans[j]]
    i -= 1
print((ans[0]+1))

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

# Douling(ダブリング)
i = 1
to = [[a for a in A]]
while pow(2, i) < K:
    t = [to[i-1][to[i-1][j]] for j in range(N)]
    to.append(t)
    i += 1

i -= 1
ans = 0
while i >= 0:
    if K & (1 << i) > 0:
        ans = to[i][ans]
    i -= 1
print((ans+1))