CodeEff/ECCO huggingface dataset:
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

towns = [0] * n
i = 0
cnt = 1
towns[0] = cnt
nums = [1]
while True:
    cnt += 1
    i = a[i] - 1
    if towns[i] == 0:
        towns[i] = cnt
        nums.append(i + 1)
    else:
        s_loop = nums.index(i + 1)
        m = len(nums)
        l = m - s_loop
        break

if k < len(nums):
    print((nums[k]))
else:
    k -= m - 1
    k = (k - 1) % l
    print((nums[s_loop + k]))

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

flag = [0] * n
i = 0
loop = [1]
while True:
    i = a[i] - 1
    if flag[i] == 0:
        flag[i] = 1
        loop.append(i + 1)
    else:
        start = loop.index(i + 1)
        m = len(loop)
        length = m - start
        break

if k < m:
    print((loop[k]))
else:
    k -= m - 1
    k = (k - 1) % length
    print((loop[start + k]))
# Original solution
n,k=list(map(int,input().split()))
arr=list(map(int,input().split()))
for i in range(n):
  arr[i]-=1
flag=format(k,'b')
flag=flag[::-1]
pos=0
for i in range(len(flag)):
  if flag[i]=='1':
    pos=arr[pos]
  tmp=[]
  for j in range(n):
    tmp.append(arr[arr[j]])
  arr=tmp
print((pos+1))

# Optimized solution
n,k=list(map(int,input().split()))
arr=list(map(int,input().split()))
l=[-1]*(n+1)
tmp=[]
pos=1
cnt=0
while 1:
  if l[pos]!=-1:
    t=cnt-l[pos]
    if k<cnt:
      print((tmp[k]))
    else:
      print((tmp[l[pos]+(k-cnt)%t]))
    break
  l[pos]=cnt
  cnt+=1
  tmp.append(pos)
  pos=arr[pos-1]
# Original solution
# -*- coding: utf-8 -*-
import sys

(N, K) = (int(i) for i in input().split())

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

# 一周する数を求める
have_been = [1]
now_place = 1
while True:
    next_place = A[now_place - 1]
    if next_place not in have_been:
        have_been.append(next_place)
        now_place = next_place
    else:
        break

#print('have_been = {}'.format(have_been))
loop_start_index = have_been.index(next_place)

loop = have_been[loop_start_index:]
#print('loop = {}'.format(loop))

left_K = K - loop_start_index
if left_K <= 0:
    print((have_been[K]))
    sys.exit()

mod = left_K % len(loop)
print((have_been[mod + loop_start_index]))

# Optimized solution
# -*- coding: utf-8 -*-
import sys

(N, K) = (int(i) for i in input().split())

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

# 一周する数を求める
have_been = set()
have_been_list = []
have_been.add(1)
have_been_list.append(1)
now_place = 1
while True:
    next_place = A[now_place - 1]
    if next_place not in have_been:
        have_been.add(next_place)
        have_been_list.append(next_place)
        now_place = next_place
    else:
        break

#print('have_been = {}'.format(have_been))
loop_start_index = have_been_list.index(next_place)

loop_length = len(have_been_list) - loop_start_index
#print('loop = {}'.format(loop))

left_K = K - loop_start_index
if left_K <= 0:
    print((have_been_list[K]))
    sys.exit()

mod = left_K % loop_length
print((have_been_list[mod + loop_start_index]))
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

index = 1
route = [index]
node = [index]

for i in range(1, K + 1):
    index = A[index - 1]
    if index in node:
        pre = route.index(index)
        loop = len(route)
        route_idx = (K - pre) % (loop - pre) + pre
        print((route[route_idx]))
        break
    else:
        route.append(index)
        node.append(index)
else:
    print(index)

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

index = 1
route = [index]
node = {index}

for i in range(1, K + 1):
    index = A[index - 1]
    if index in node:
        pre = route.index(index)
        loop = len(route)
        route_idx = (K - pre) % (loop - pre) + pre
        print((route[route_idx]))
        break
    else:
        route.append(index)
        node.add(index)
else:
    print(index)
# Original solution
import array
n, k = list(map(int, input().split()))
tel = array.array('i', list(map(int, input().split())))
log = array.array('i', [1])
end = True
while(end):
    log.append(tel[log[-1] - 1])
    for i in range(len(log) - 1):
        if(log[i] == log[-1]):
            star = i
            mod = len(log) - star - 1
            end = False
if(k < len(log)):
    print((log[k]))
else:
    print((log[(k - star) % mod + star]))


# Optimized solution
n, k = list(map(int, input().split()))
tel = list(map(int, input().split()))
log = [1]
record = [0] * n
while(True):
    log.append(tel[log[-1] - 1])
    if(record[log[-1] - 1] == 1):
        break
    record[log[-1] - 1] += 1
for i in range(len(log) - 1):
    if(log[i] == log[-1]):
        star = i
        mod = len(log) - star - 1
        break
if(k < len(log)):
    print((log[k]))
else:
    print((log[(k - star) % mod + star]))
# Original solution
import bisect
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
seen = []
seen_sort = [1]
start = 1

while True:
    tmp = a[start - 1]
    seen.append(start)
    index = bisect.bisect_left(seen_sort, tmp)
    if index >= len(seen_sort) or seen_sort[index] != tmp:
        seen_sort.insert(index, tmp)
    else:
        repeat_index = seen.index(tmp)
        repeat_len = len(seen) - repeat_index
        break
    start = tmp

if k <= repeat_index:
    print((seen[k]))
else:
    print((seen[repeat_index + ((k - repeat_index) % repeat_len)]))

# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
visited = []
visited_index = [-1] * n
pre = 0

while visited_index[pre] == -1:
    now = a[pre]
    visited.append(pre)
    visited_index[pre] = len(visited)
    pre = now - 1

loop = len(visited) - visited_index[pre] + 1
head = visited_index[pre] - 1

if k < head:
    print((visited[k] + 1))
else:
    k -= head
    k %= loop
    print((visited[head + k] + 1))
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

zumi = [-1]*(2*(10**5))
ima = 1
for i in range(K):
    # 行ったことある町を通る＝ループする
    if ima in zumi:
        zumi[i] = ima
        break
    # 同じ町へテレポートしている
    if ima == A[ima-1]:
        print(ima)
        exit(0)
    zumi[i] = ima
    ima = A[ima-1]
else:
    print(ima)
    exit(0)

loop_e = zumi.index(-1)
loop_s = zumi.index(zumi[loop_e-1])
zan_loop = K-loop_s
loop = zumi[loop_s:loop_e-1]
amari = zan_loop % (len(loop))
print((loop[amari]))


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

zumi_hash = {}
zumi = [-1]*(2*(10**5))
ima = 1
for i in range(K):
    # 行ったことある町を通る＝ループする
    if ima in zumi_hash:
        zumi[i] = ima
        break
    # 同じ町へテレポートしている
    if ima == A[ima-1]:
        print(ima)
        exit(0)
    zumi_hash[ima] = True
    zumi[i] = ima
    ima = A[ima-1]
else:
    print(ima)
    exit(0)

loop_e = zumi.index(-1)
loop_s = zumi.index(zumi[loop_e-1])
zan_loop = K-loop_s
loop = zumi[loop_s:loop_e-1]
amari = zan_loop % (len(loop))
print((loop[amari]))
# Original solution
N,K = list(map(int, input().split()))
A = list(map(int, input().split()))

loc = 1
loclog=[1]
flag = 0

for i in range(K):
    loc = A[loc-1]
    if loc in loclog:
        roopstart = loclog.index(loc)
        roopend = len(loclog)
        flag = 1
        break
    loclog.append(loc)

if flag == 0:
    ans = loc
else:
    roopidx = (K+1-roopstart)%(roopend-roopstart)
    if roopidx == 0:
        ans = loclog[roopend-1]
    else:
        ans = loclog[roopstart+roopidx-1]
print(ans)

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

loc = 1
loclog=[1]
flag = 0
hist = [0]*N

for i in range(K):
    hist[loc-1] = 1
    loc = A[loc-1]
    if hist[loc-1] != 0:
        roopstart = loclog.index(loc)
        roopend = len(loclog)
        flag = 1
        break
    loclog.append(loc)

if flag == 0:
    ans = loc
else:
    roopidx = (K+1-roopstart)%(roopend-roopstart)
    if roopidx == 0:
        ans = loclog[roopend-1]
    else:
        ans = loclog[roopstart+roopidx-1]
print(ans)
# Original solution
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
dict={}
for i in range(n):
    dict[i]=a[i]-1 #i番目の町からどこにつくか
tmp=0#現在知
num2city={}
city2num={}
city2num[0]=0#どのまちが何回目か
num2city[0]=0#j回目にどこにいるか
for j in range(1,k+1):
    if tmp==dict[tmp]:
        break
    tmp=dict[tmp]#現在地更新
    if tmp not in list(num2city.values()):#現在地がまだきたことない
        num2city[j]=tmp
        city2num[tmp]=j
    else:
        mae=city2num[tmp]
        term=j-mae 
        res=k-j
        r=res%term
  #      print(mae,term,res,r,mae+r,num2city[mae+r])
        tmp=num2city[mae+r]
 #       print(tmp)
        break
   # print(tmp+1)
    
#print(num2city)
#print(city2num)
print((tmp+1))



# Optimized solution
n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
dict={}
for i in range(n):
    dict[i]=a[i]-1 #i番目の町からどこにつくか
tmp=0#現在知
num2city={}
city2num={}
city2num[0]=0#どのまちが何回目か
num2city[0]=0#j回目にどこにいるか
alre=[-1]*n
alre[0]=1
for j in range(1,k+1):
    if tmp==dict[tmp]:
        break
    tmp=dict[tmp]#現在地更新
    if alre[tmp]==-1:#tmp not in num2city.values():#現在地がまだきたことない
        alre[tmp]=1
        num2city[j]=tmp
        city2num[tmp]=j
    else:
        mae=city2num[tmp]
        term=j-mae 
        res=k-j
        r=res%term
  #      print(mae,term,res,r,mae+r,num2city[mae+r])
        tmp=num2city[mae+r]
 #       print(tmp)
        break
   # print(tmp+1)
    
#print(num2city)
#print(city2num)
print((tmp+1))
# Original solution
n, k = list(map(int,input().split()))
a = list(map(int,input().split()))

s = [-1] * n
c = [1]
t = 0
now = 0
while s[now] == -1:
    s[now] = t
    now = a[now] - 1
    c.append(now+1)
    t += 1

start_cycle = c.index(c[-1])
loop = c[start_cycle:-1]
cycle = len(loop)

if k < start_cycle:
    print((c[k]))
else:
    k -= start_cycle
    k %= cycle
    print((loop[k]))

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

s = [False] * n
c = [1]
now = 0
while not s[now]:
    s[now] = True
    now = a[now] - 1
    c.append(now+1)

start_cycle = c.index(c[-1])
loop = c[start_cycle:-1]
cycle = len(loop)

if k < start_cycle:
    print((c[k]))
else:
    k -= start_cycle
    k %= cycle
    print((loop[k]))
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

current = 1
path = [1]

while K > 0:
    if A[current - 1] in path:
        loop = path[path.index(A[current - 1]):]
        path += [loop[(K-1) % len(loop)]]
        break

    path += [A[current - 1]]
    current = A[current - 1]
    K -= 1

print((path[-1]))


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

current = 1
path = [1]
already = [False] * len(A)

while K > 0:
    if already[current - 1]:
        loop = path[path.index(A[current - 1]):]
        current = loop[(K - 1) % len(loop)]
        break

    path += [A[current - 1]]
    already[current - 1] = True
    current = A[current - 1]
    K -= 1

print(current)
# Original solution
n,k=list(map(int,input().split()))
a=list([int(x)-1 for x in input().split()])
town=[0]
i=0
while True:
  idx=town[-1]
  if a[idx] in town:
    s=a[idx]
    i+=1
    break
  else:
    i+=1
    town.append(a[idx])
if i!=n:
  idp=town.index(s)
  chain=len(town[:idp])
  cycle=len(town[idp:])
  if k<=chain:
    print((town[k]+1))
  else:
    p=(k-chain)%cycle + chain
    print((town[p]+1))
else:
  print((town[k%n]+1))

# Optimized solution
n,k=list(map(int,input().split()))
a=list([int(x)-1 for x in input().split()])
town=[0]
set={0}
i=0
while True:
  idx=town[-1]
  if a[idx] in set:
    s=a[idx]
    i+=1
    break
  else:
    i+=1
    town.append(a[idx])
    set.add(a[idx])
if i!=n:
  idp=town.index(s)
  chain=len(town[:idp])
  cycle=len(town[idp:])
  if k<=chain:
    print((town[k]+1))
  else:
    p=(k-chain)%cycle + chain
    print((town[p]+1))
else:
  print((town[k%n]+1))
# Original solution
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=lambda x:int(math.floor(x)),lambda x:int(math.ceil(x))
from functools import reduce;gcd=lambda*x:reduce(math.gcd,x);lcm=lambda*x:reduce(lambda x,y:(x*y)//gcd(x,y),x,1)
from collections import deque
import bisect
Yes=lambda b:print("Yes"if b else"No");YES=lambda b:print("YES"if b else"NO")
is_even=lambda x:True if x%2==0 else False

def main():
    n,k=ints()
    a=ints()
    passed=[]
    flg=0
    p=0
    while flg==0:
        if p in passed:
            flg=1
            s=passed.index(p)
            break
        else:
            passed.append(p)
            p=a[p]-1
    l=len(passed)
    if k<l:
        print(passed[k]+1)
    else:
        print(passed[(k-s)%(l-s)+s]+1)

if __name__ == '__main__':
    main()


# Optimized solution
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=lambda x:int(math.floor(x)),lambda x:int(math.ceil(x))
from functools import reduce;gcd=lambda*x:reduce(math.gcd,x);lcm=lambda*x:reduce(lambda x,y:(x*y)//gcd(x,y),x,1)
from collections import deque
import bisect
Yes=lambda b:print("Yes"if b else"No");YES=lambda b:print("YES"if b else"NO")
is_even=lambda x:True if x%2==0 else False

def main():
    n,k=ints()
    a=ints()
    passed=[]
    flg=0
    p=0
    while flg==0:
        if a[p] == 'passed':
            flg=1
            s=passed.index(p)
            break
        else:
            passed.append(p)
            pp=p
            p=a[pp]-1
            a[pp]='passed'
    l=len(passed)
    if k<l:
        print(passed[k]+1)
    else:
        print(passed[(k-s)%(l-s)+s]+1)

if __name__ == '__main__':
    main()
# Original solution
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N,K=list(map(int,readline().split()))
A=list([int(x)-1 for x in readline().split()])

visited=[True]*N
visitednum=[]
now=0
cnt=0
while True:
    if visited[now]==False:
        break
    else:
        visited[now]=False
        visitednum.append(now)
        now=A[now]
        cnt+=1
loop=[]
while True:
    if now in loop:
        break
    loop.append(now)
    now=A[now]
if K<cnt:
    print((visitednum[K]+1))
else:
    t=(K-(len(visitednum)+len(loop)))%len(loop)
    print((loop[t]+1))

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

num = 1
li = [1]
flag = [True] * n
flag[0] = False

for i in range(k):
    num = a[num-1]
    if flag[num-1]:
        li.append(num)
        flag[num-1] = False
    else:
        break

d = li.index(num)
ans = (k-d)%(len(li)-d)+d

print((li[ans]))
# Original solution
def ans(n, k, list_a):
    i=0
    list_memo=[1]
    while i<k:
        next = list_a[list_memo[i]-1]
        if next not in list_memo:
            list_memo.append(next)
        else:
            num=list_memo.index(next)
            len_list=len(list_memo)
            i+=1
            x = len_list-num
            k=k-num
            
            #print(k)
            k%=x
            return list_memo[num+k]
            #return 50000
            
        i+=1
    return list_memo[i]
        




n, k = (int(x) for x in input().split())
list_a = list(map(int, input().split()))
print((ans(n, k, list_a)))

# Optimized solution
def ans(n, k, list_a):
    i=0
    dic={}
    dic[1]=1
    list_memo=[1]
    while i<k:
        next = list_a[list_memo[i]-1]
        if next not in dic:
            list_memo.append(next)
            dic[next]=1
        else:
            num=list_memo.index(next)
            len_list=len(list_memo)
            i+=1
            x = len_list-num
            k=k-num
            
            #print(k)
            k%=x
            return list_memo[num+k]
            #return 50000
            
        i+=1
    return list_memo[i]
        




n, k = (int(x) for x in input().split())
list_a = list(map(int, input().split()))
print((ans(n, k, list_a)))
# Original solution
n, k = list(map(int, input().split()))
A=list(map(int, input().split()))

c=1
path=[]
d={}
l=0
while l<=k:
    if c in path:
        p=d[c]
        #print(p, path)
        pattern_l = l-p
        k-=((k-p)//pattern_l)*pattern_l
    path.append(c)
    l+=1
    d[c]=l-1
    c=A[c-1]
print((path[k]))


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

c=1
path=[]
d={}
l=0
while l<=k:
    if c in d:
        p=d[c]
        #print(p, path)
        pattern_l = l-p
        k-=((k-p)//pattern_l)*pattern_l
    path.append(c)
    l+=1
    d[c]=l-1
    c=A[c-1]
print((path[k]))
# Original solution
n,k=list(map(int,input().split()))
A=list(map(int,input().split()))
cnt=0
s=1
M=[0]
B=[0]*(n+1)
while cnt<n:
    s=A[s-1]
    if B[s-1]==0:
        B[s-1]+=1
    else:
        imp=s-1
        break
    M.append(s-1)
    cnt+=1
x=M.index(imp)
y=len(M)-x

if k<=x:
    print((M[k]+1))
else:
    N=M[x:]
    print((N[(k-x)%y]+1))

# Optimized solution
n,k=list(map(int,input().split()))
A=list(map(int,input().split()))
cnt=0
s=1
M=[0]
B=[False]*(n+1)
while cnt<n:
    s=A[s-1]
    if not B[s-1]:
        B[s-1]=True
    else:
        break
    M.append(s-1)
    cnt+=1
x=M.index(s-1)
y=len(M)-x

if k<=x:
    print((M[k]+1))
else:
    N=M[x:]
    print((N[(k-x)%y]+1))
# Original solution
from collections import defaultdict


def inpl():
    return list(map(int, input().split()))


N, K = inpl()
aa = inpl()

s = 1

route = [s]
ed = set([s])

for i in range(1, K + 1):
    s = aa[s - 1]
    if s in ed:
        Li = route.index(s)
        Ri = len(route)
        idx = Li + (K - Li) % (Ri - Li)
        print((route[idx]))
        break
    else:
        route.append(s)
        ed.add(s)
        continue
else:
    print(s)


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

visited= [1]
ed = set([1])
for i in range(K):
    next_town  = al[visited[i] - 1]
    if next_town in ed:
        loop_sta = visited.index((next_town)) #　visited_townsにおけるループ開始のインデックス
        loop_end = len(visited) #visited_townsにおけるループの終わりのインデックス
        loop_length = loop_end - loop_sta #繰り返すループの長さ
        amari = (K - loop_sta) % loop_length
        ans = visited[loop_sta + amari]
        print(ans)
        exit()
    else:
        visited.append(next_town)
        ed.add(next_town)
        continue

else:
    print((visited[-1]))
# Original solution
from sys import stdin

def main():
    n, k = list(map(int, stdin.readline().rstrip().split()))
    a = [int(x)-1 for x in stdin.readline().rstrip().split()]
    n = a[0]
    his = [-1, n]
    f = his.append
    while True:
        n = a[n]
        if n in his:
            f(n)
            break
        f(n)
    idx = his.index(his[-1])
    loop = len(his[his.index(his[-1]):-1])
    if len(his) > k:
        print((his[k]+1))
    else:
        t = (k - idx) % loop
        g = his[idx:-1]
        print((g[t]+1))
main()

# Optimized solution
from sys import stdin

def main():
    n, k = list(map(int, stdin.readline().rstrip().split()))
    a = [int(x)-1 for x in stdin.readline().rstrip().split()]
    n = a[0]
    his = [-1, n]
    f = his.append
    s = set()
    while True:
        n = a[n]
        if n in s:
            f(n)
            break
        f(n)
        s.add(n)
    idx = his.index(his[-1])
    loop = len(his[his.index(his[-1]):-1])
    if len(his) > k:
        print((his[k]+1))
    else:
        t = (k - idx) % loop
        g = his[idx:-1]
        print((g[t]+1))
main()
# Original solution
N,K = [int(i) for i in input().split(' ')]
A = [int(i) for i in input().split(' ')]
 
where_li = []
pre = 0
for i in range(N):
	where_li.append(A[pre])
	pre = A[pre]-1

aa = sorted([x for x in set(where_li) if where_li.count(x) > 1], key=where_li.index)
if(len(aa)==0):
	indexes = [0,0]
else:
	indexes = [i for i, x in enumerate(where_li) if x == aa[0]]
where_li = where_li[:indexes[1]]
len_w = len(where_li)
mod_s = len_w-indexes[0]
if K<=len_w:
	print((where_li[K-1]))
else:
	if (K-len_w)%mod_s==0:
		d = mod_s
	else:
		d = (K-len_w)%mod_s
	print((where_li[d-1+indexes[0]]))

# Optimized solution
N,K = [int(i) for i in input().split(' ')]
A = [int(i) for i in input().split(' ')]
 
where_li = []
pre = 0
for i in range(N):
	where_li.append(A[pre])
	pre = A[pre]-1

len_w = len(where_li)
a = where_li.index(A[pre])
mod_s = len_w-a
if K<=len_w:
	print((where_li[K-1]))
else:
	if (K-len_w)%mod_s==0:
		d = mod_s
	else:
		d = (K-len_w)%mod_s
	print((where_li[d-1+a]))
# Original solution
import sys

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

alr = []
now = 1
i = 0
while not now in alr:
    alr.append(now)
    now = A[now-1]
    i += 1
    if i == K:
        print(now)
        sys.exit()

place = alr.index(now)
circle = len(alr) - place
rem = (K - place) % circle
print((alr[place + rem]))

# Optimized solution
import sys

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

alr = {}
now = 1
i = 0
while not now in list(alr.keys()):
    alr[now] = i
    now = A[now-1]
    i += 1
    if i == K:
        print(now)
        sys.exit()

place = alr[now]
circle = len(alr) - place
rem = (K - place) % circle
for k, v in list(alr.items()):
    if v == place + rem:
        print(k)
        break
# Original solution
a = input().split(" ")
N = eval(a[0])
K = eval(a[1])
dic = {}
b = input().split(" ")
for i in range(1, N + 1):
    dic[i] = eval(b[i - 1])
ans = 1
lst = []
length = 0
while K > 0:
    if ans in lst:
        left = lst.index(ans)
        right = length
        zq = right - left
        K = K % zq
        if K == 0:
            break
    else:
        lst.append(ans)
        length += 1
    ans = dic[ans]
    K -= 1

print(ans)

# Optimized solution
a = input().split(" ")
N = eval(a[0])
K = eval(a[1])
dic = {}
b = input().split(" ")
n_lst = [-1]
for i in range(1, N + 1):
    dic[i] = eval(b[i - 1])
    n_lst.append(-1)
ans = 1
lst = []
length = 0
while K > 0:
    if n_lst[ans] != -1:
        left = n_lst[ans]
        zq = length - left
        K = K % zq
        if K == 0:
            break
    else:
        n_lst[ans] = length
        length += 1
    ans = dic[ans]
    K -= 1

print(ans)
# Original solution
def main():
    import sys
    input = sys.stdin.readline

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


    visited = [0]
    now = 0
    ind = 0
    my_append = visited.append
    for _ in range(K):
        a = A[now]-1
        if a in visited:
            ind = visited.index(a)
            break
        else:
            my_append(a)
            now = a

    loop_visited = visited[ind:]
    ans_ind = (K-ind) % len(loop_visited)

    print((loop_visited[ans_ind]+1))


if __name__ == "__main__":
    main()


# Optimized solution
def main():
    import sys
    input = sys.stdin.readline

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

    # N = 2*(10**4)
    # K = 10**18
    # A = [i+2 for i in range(N)]
    # A[-1] = 1
    # print(A)

    visited = [0]
    visited_set = set([0])
    now = 0
    ind = 0
    my_append = visited.append
    my_add = visited_set.add
    for i in range(K):
        a = A[now]-1
        if a in visited_set:
            ind = visited.index(a)
            break
        else:
            my_add(a)
            my_append(a)
            now = a
            # ind = i

    loop_visited = visited[ind:]
    ans_ind = (K-ind) % len(loop_visited)

    print((loop_visited[ans_ind]+1))


if __name__ == "__main__":
    main()