CodeEff/ECCO huggingface dataset:
# Original solution
import sys

n, k = list(map(int, input().split()))
ara = [0]
ara += list(map(int, input().split()))

now = 1
vis = []
taken = [0]*(n+1)

while taken[now] == 0:
    vis.append(now)
    taken[now] = 1
    now = ara[now]

cycleLen = len(vis) - vis.index(now)

if k < vis.index(now):
    print((vis[k]))
    sys.exit()

k -= vis.index(now)
k %= cycleLen

print((vis[k + vis.index(now)]))

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

# mp = dict()
# for ix in range(N):
#     mp[ix+1] = A[ix]

hist = []
exists = [0] * (N+1)
cur = 1
cnt = 0

# ここがおかしい?
# while True:
#     cur = mp[cur]
#     cnt += 1
#     # K -= 1

#     if exists[cur] != 0:
#         break
#     else:
#         exists[cur] = 1
#         hist.append(cur)

A = [0] + A
# print(A)
while exists[cur] == 0:
    hist.append(cur)
    exists[cur] = 1
    cur = A[cur]

cycle_sp = cur
# cycle_l = 0
cycle_sp_ix = hist.index(cycle_sp)

import sys
if K < cycle_sp_ix:
    print((hist[K]))
    sys.exit()

cycle_l = len(hist) - cycle_sp_ix
# while True:
#     cur = mp[cur]
#     cycle_l += 1

#     if cur == cycle_sp:
#         break

rest = (K-cycle_sp_ix) % cycle_l
# print("cnt:", cnt)

# print("K:", K)
# print("cycle_l:", cycle_l)
# print("rest:", rest)

print((hist[rest + cycle_sp_ix]))
# while rest != 0:
#     cur = mp[cur]
#     rest -= 1

# print(cur)




"""
# hist = [1]
hist = {1: 0}
while True:

    hk = hist.keys()[-1]

    if not mp[hk] in hist.keys():
        # hist.append(mp[hist[-1]])
        hist[mp[hk]] = 0

    else:
        # found
        cstart = hist.index(mp[hk])
        cend = len(hist)
        cycle_l = cend - cstart
        # print("hist:", hist)
        # print("cstart:", cstart)
        # print("cend:", cend)
        # print("cycle_l:", cycle_l)

        ans_i = (K - cstart) % cycle_l
        # print("ans_i:", ans_i)
        ans = hist[cstart + ans_i]

        print(ans)
        break
"""
# Original solution
from collections import defaultdict
def main():
    n, k = list(map(int, input().split(" ")))
    a = list([int(i)-1 for i in input().split(" ")])
    s = [0]
    d = defaultdict(lambda:0)
    x = a[0]
    for i in range(n):
        s.append(x)
        x = a[x]

    bb=None
    for i in range(n):
        d[s[i]] += 1
        if d[s[i]] ==2:
            bb=s[i]
            break

    cc = s.index(bb)
    s[cc]=-1
    dd = s.index(bb)
    loop_len = dd-cc
    s[cc]=s[dd]
        
    if bb ==None or k < cc:
        print((s[k]+1))
    else:
        y = (k-cc) % loop_len
        print((s[y+cc]+1))

if __name__ == "__main__":
    main()

# Optimized solution
from collections import defaultdict
def main():
    n, k = list(map(int, input().split(" ")))
    a = list(map(int, input().split(" ")))
    s = []
    ord = [-1]*(n+1)
    u = 1
    while ord[u] == -1:
        ord[u] = len(s)
        s.append(u)
        u = a[u-1]
    l = len(s) - ord[u]
    if k < ord[u]:
        print((s[k]))
    else:
        print((s[(k-ord[u])%l+ord[u]]))

'''
def main():
    n, k = map(int, input().split(" "))
    a = list(map(lambda i: int(i)-1, input().split(" ")))
    s = [0]
    d = defaultdict(lambda:0)
    x = a[0]
    for i in range(n):
        s.append(x)
        x = a[x]

    bb=None
    for i in range(n):
        d[s[i]] += 1
        if d[s[i]] ==2:
            bb=s[i]
            break

    cc = s.index(bb)
    s[cc]=-1
    dd = s.index(bb)
    loop_len = dd-cc
    s[cc]=s[dd]
        
    if bb ==None or k < cc:
        print(s[k]+1)
    else:
        y = (k-cc) % loop_len
        print(s[y+cc]+1)
'''
if __name__ == "__main__":
    main()
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
idx = A[0]
move = []
move.append(idx)
cycle = []
for _ in range(K-1):
  idx = A[idx-1]
  if idx in move:
    cycle = move[move.index(idx):]
    break
  move.append(idx)

if cycle:
  print((cycle[(K - 1- (len(move)-len(cycle)))%len(cycle)]))
else:
  print((move[K-1]))

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

R = [False]*(N+1)
D = []
p = 1
while True:
    if R[p]:
        break
    D.append(p)
    R[p] = True
    p = A[p-1]
m = D.index(p)
c = len(D)-m

if K <= m:
    print((D[K]))
else:
    print((D[m+(K-m) % c]))
# Original solution
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline 

n,k,*a = list(map(int,read().split()))
for i in range(n): a[i] -= 1

def pow2(a,n):
    if n==0: return list(range(n))
    if n==1: return a
    if n%2:
        return mul(a,pow2(a,n-1))
    else:
        x = pow2(a,n//2)
        return mul(x,x)

def mul(a,b):
    return [a[bi] for bi in b]

x = pow2(a,k)
print((x[0]+1))

# Optimized solution
# coding: utf-8
# Your code here!
import sys
read = sys.stdin.read
readline = sys.stdin.readline 

n,k,*a = list(map(int,read().split()))
for i in range(n): a[i] -= 1

na = [0]*n
v = 0
while k:
    if k&1: v = a[v]
    for j, aj in enumerate(a):
        na[j] = a[aj]
    a,na = na,a
    i += 1    
    k >>= 1

print((v+1))
# Original solution
from collections import Counter
N, K = list(map(int,input().split()))
A = list(map(int,input().split()))
i = k = 0
B = [1]
while k <= 10 ** 6:
    i = A[i] - 1
    B.append(i + 1)
    k += 1
S = Counter(B)
idx = S.most_common(1)[0][0]
i = k = cnt = 0
k_s = None
while k < 10 ** 6:
    if B[k] == idx and cnt == 1:
        k_s = k
        break
    elif B[k] == idx:
        k_f = k
        cnt += 1
    k += 1
if k_s and k_s < K:
    k_max = (K - B.index(idx)) % (k_s - k_f) + B.index(idx)
else:
    k_max = K
i = k = 0
while k < k_max:
    i = A[i] - 1
    k += 1
print((i + 1)) 

# Optimized solution
from collections import Counter
N, K = list(map(int,input().split()))
A = list(map(int,input().split()))
i = k = 0
B = [1]
while k <= N:
    i = A[i] - 1
    B.append(i + 1)
    k += 1
S = Counter(B)
idx = S.most_common(1)[0][0]
i = k = cnt = 0
k_s = None
while k < N:
    if B[k] == idx and cnt == 1:
        k_s = k
        break
    elif B[k] == idx:
        k_f = k
        cnt += 1
    k += 1
if k_s and k_s < K:
    k_max = (K - B.index(idx)) % (k_s - k_f) + B.index(idx)
else:
    k_max = K
i = k = 0
while k < k_max:
    i = A[i] - 1
    k += 1
print((i + 1))
# Original solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

route = [1]
index = k
for i in range(n+1):
    _next = a[route[-1]]
    if _next in route:
        route.append(_next)
        index -= (i+1)
        break
    route.append(_next)

if index <= 0:
    print((route[k]))
else:
    route = route[route.index(route[-1]):-1]
    print((route[index % len(route)]))


# Optimized solution
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

route = [1]
index = k
hit = set([1])
for i in range(n+1):
    _next = a[route[-1]]
    if _next in hit:
        route.append(_next)
        index -= (i+1)
        break
    route.append(_next)
    hit.add(_next)

if index <= 0:
    print((route[k]))
else:
    route = route[route.index(route[-1]):-1]
    print((route[index % len(route)]))
# Original solution
#!/usr/bin/env python3
import math

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N, K = list(map(int, input().split()))
    A = [int(i) for i in input().split()]

    dv = []
    for _ in range(int(math.log2(K)) + 1):
        l = [0] * N
        dv.append(l)
    
    for n in range(N):
        dv[0][n] = A[n] - 1
    
    for k in range(1, int(math.log2(K)) + 1):
        for n in range(N):
            dv[k][n] = dv[k - 1][dv[k - 1][n]]
    
    a = []
    for i in range(60):
        if K>>i & 1:
            a.append(i)

    now = 0
    for i in reversed(a):
        now = dv[i][now]
    print((now + 1))





    pass

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin/env python3
import math

# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    N, K = list(map(int, input().split()))
    A = [int(i) for i in input().split()]

    dv = []
    for _ in range(60):
        l = [0] * N
        dv.append(l)
    
    for n in range(N):
        dv[0][n] = A[n] - 1
    
    for k in range(1, 60):
        for n in range(N):
            dv[k][n] = dv[k - 1][dv[k - 1][n]]
    
    a = []
    for i in range(60):
        if K>>i & 1:
            a.append(i)

    now = 0
    for i in a:
        now = dv[i][now]
    print((now + 1))

    return

if __name__ == '__main__':
    main()
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
v = []
now = 0
for i in range(K):
  p = A[now]
  now = p-1
  if p in v:
    j = v.index(p)
    df = i-j
    Kn = (K-i-1) % df
    p = v[j+Kn]
    break
  else:
  	v.append(p)
print(p)

# Optimized solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
v = []
w = {}
now = 0
for i in range(K):
  p = A[now]
  now = p-1
  if p in w:
    j = v.index(p)
    df = i-j
    Kn = (K-i-1) % df
    p = v[j+Kn]
    break
  else:
    v.append(p)
    w[p] = p
print(p)
# Original solution
n, k = list(map(int, input().split()))
L= list(map(int, input().split()))
S=[]
S.append(1)
p=0
cnt=0
for i in range(n):
	if L[p] in S:
		cnt+=1
		S.append(L[p])
		break
	else:
		cnt+=1
		S.append(L[p])
		p=L[p]-1

cnt2=0
for i in range(n):
	if S[i]!=L[p]:
		cnt2+=1
	else:
		S2=S[i:]
		break
loop=len(S)-cnt2-1


if cnt>=k:
	print((S[k]))
else:
	print((S2[(k-cnt)%loop]))

# Optimized solution
n, k = list(map(int, input().split()))
L= list(map(int, input().split()))
S=[]
S.append(1)
Q=set()
Q.add(1)
p=0
cnt=0
for i in range(n):
	if L[p] in Q:
		cnt+=1
		S.append(L[p])
		break
	else:
		cnt+=1
		S.append(L[p])
		Q.add(L[p])
		p=L[p]-1

cnt2=0
for i in range(n):
	if S[i]!=L[p]:
		cnt2+=1
	else:
		S2=S[i:]
		break
loop=len(S)-cnt2-1


if cnt>=k:
	print((S[k]))
else:
	print((S2[(k-cnt)%loop]))
# Original solution
import sys


def input():
    return sys.stdin.readline().strip()


N, K = list(map(int, input().split()))
k_bitlen = K.bit_length()
dp = [[0] * N for _ in range(k_bitlen + 1)]
dp[0] = list([int(x) - 1 for x in input().split()])

for k in range(k_bitlen):
    for i in range(N):
        dp[k + 1][i] = dp[k][dp[k][i]]
pos = 0
for k in range(k_bitlen):
    if K >> k & 1:
        pos = dp[k][pos]
print((pos + 1))

# Optimized solution
import sys


sys.setrecursionlimit(10 ** 6)


def dfs(v):
    path.append(v)
    visited[v] = 1
    nv = A[v]
    if visited[nv] == 1:
        return nv
    return dfs(nv)


N, K = list(map(int, input().split()))
A = list([int(x) - 1 for x in input().split()])
visited = [0] * N
path = []
cycle_start = dfs(0)
cycle_len = len(path) - path.index(cycle_start)
head_len = len(path) - cycle_len
if K <= head_len:
    print((path[K] + 1))
else:
    K -= head_len
    print((path[head_len + K % cycle_len] + 1))
# Original solution
import sys
from collections import deque

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

graph = {}
count = 1
for value in input().split():
    graph[count] = int(value)
    count += 1

queue = deque()
queue.append(1)
now_pos = 1
start = 0

for i in range(N + 1):
    next_pos = graph[now_pos]
    if not next_pos in queue:
        queue.append(next_pos)
        now_pos = next_pos

    # 循環した
    else:
        start = next_pos
        break

if K <= N:
    print((queue[K]))
    sys.exit()

before_len = queue.index(start)
roop = len(queue) - before_len

print((queue[before_len + (K - before_len) % roop]))


# Optimized solution
import sys
import time

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

queue = {}

start = -1
count = 1

now_town = 1

for i in range(K):
    if town_list[now_town - 1] in queue:
        start = town_list[now_town - 1]
        break
    queue[town_list[now_town - 1]] = count
    now_town = town_list[now_town - 1]
    count += 1

if start == -1:
    print(now_town)
    sys.exit()

roop = len(queue) - (queue[start] - 1)
before_len = queue[start]

print((list(queue.keys())[(K - before_len) % roop + before_len - 1]))
# Original solution
def f():
    n,k=list(map(int,input().split()))
    l=list(map(int,input().split()))
    now=1

    for i in range(k.bit_length()):
        if k%2:now=l[now-1]
        l=[l[l[i]-1]for i in range(n)]
        k//=2
    print(now)
if __name__ == "__main__":
    f()

# Optimized solution
def f():
    n,k=list(map(int,input().split()))
    l=list(map(int,input().split()))
    now=1

    for i in range(k.bit_length()):
        if k%2:now=l[now-1]
        l=tuple(l[l[i]-1]for i in range(n))
        k//=2
    print(now)
if __name__ == "__main__":
    f()
# Original solution
def f():
    n,k=list(map(int,input().split()))
    l=list(map(int,input().split()))
    now=1

    for i in range(k.bit_length()):
        if k%2:now=l[now-1]
        l=tuple(l[l[i]-1]for i in range(n))
        k//=2
    print(now)
if __name__ == "__main__":
    f()

# Optimized solution
def f():
    n,k=list(map(int,input().split()))
    l=list(map(int,input().split()))
    now=1
    for d in range(k.bit_length()):
        if k%2:now=l[now-1]
        l=tuple(l[i-1]for i in l)
        k//=2
    print(now)
if __name__ == "__main__":
    f()
# Original solution
n,k=list(map(int,input().split()))
A=list(map(int,input().split()))
C=[0]+[-1]*(n-1)
p=1
c=0
s=-1
e=-1
for i in range(n):
    p=A[p-1]
    c+=1
    if C[p-1]==-1:
        C[p-1]=c
    else:
        s=C[p-1]
        e=c
        break
P=1
if s!=-1 and e!=-1:
    if k<=s:
        while k>0:
            P=A[P-1]
            k-=1
        print(P)
    else:
        l=(k-s)%(e-s)
        k=s+l+1
        while k>1:
            P=A[P-1]
            k-=1
        print(P)
else:
    if k<=n:
        while k>0:
            P=A[P-1]
            k-=1
        print(P)
    else:
        while n>0:
            P=A[P-1]

# Optimized solution
n,k=list(map(int,input().split()))
A=list(map(int,input().split()))
p=1
if k<=n:
    for i in range(k):
        p=A[p-1]
    print(p)
else:
    D=[0]+[-1]*(n-1)
    for i in range(n):
        p=A[p-1]
        if D[p-1]==-1:
            D[p-1]=i+1
        else:
            l=D[p-1]
            r=i+1-D[p-1]
            m=(k-l)%r+l
            break
    p=1
    for i in range(m):
        p=A[p-1]
    print(p)
# Original solution
from collections import deque

N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
T = set([0])  # 0-indexed

c = 0  # 0-indexed
for i in range(N + 1):
    c = A[c] - 1
    # print('c', c)
    if c not in T:
        T.add(c)
    else:
        break
C = deque([c])
T = set([c])  # 0-indexed
for i in range(N + 1):
    c = A[c] - 1
    # print('c', c)
    if c not in T:
        T.add(c)
        C.append(c)
    else:
        break
c2 = 0  # 0-indexed
S = deque([0])
for i in range(N + 1):
    c2 = A[c2] - 1
    if c2 == c:
        break
    else:
        S.append(c2)
# print('C', C)
# print('S', S)
# print('len(C), len(S)', len(C), len(S))

if C[0] == 0:
    mod = K % len(C)
    ans = C[mod]
else:
    if len(S) > K:
        ans = S[K]
    else:
        mod = (K - len(S)) % len(C)
        ans = C[mod]
print((ans + 1))


# Optimized solution
import sys
input = sys.stdin.buffer.readline
N, K = list(map(int, input().split()))
A = [-1] + list(map(int, input().split()))

I = [-1] * (N + 1)
S = []
idx = 1
while I[idx] == -1:
    S.append(idx)
    I[idx] = len(S)
    idx = A[idx]
# print(f'{S=}, {idx=}, {I[idx]=}')

start_idx = I[idx] - 1
num_circles = len(S) - start_idx
# print(f'{start_idx=}, {num_circles=}')

if K < len(S) - 1:
    ans = S[K]
else:
    K -= start_idx
    div, mod = divmod(K, num_circles)
    ans = S[start_idx + mod]
print(ans)
# Original solution
n,k=list(map(int,input().split()))
A=list(map(int,input().split()))

time=0
color=["white" for _ in range(n+1)]
D=[-1 for _ in range(n+1)]
C,s=[],A[0]
point=0
while 1:
    if color[s]=="white":
        color[s]="gray"
        C.append(s)
        D[s]=time
        time +=1
        s=A[s-1]
    else:
        point=D[s]
        break

loop=C[point:]
if k>len(C):
    k -=point+1
    print((loop[k%len(loop)]))
else:print((C[k-1]))

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

time=0
color=["white" for _ in range(n+1)]
D=[-1 for _ in range(n+1)]
C,s=[],A[0]
point=0
while 1:
    if color[s]=="white":
        color[s]="gray"
        C.append(s)
        D[s]=time
        time +=1
        s=A[s-1]
    else:
        point=D[s]
        break

loop=C[point:]
if k>len(C):
    k -=point
    print((loop[k%len(loop)-1]))
else:print((C[k-1]))
# Original solution
def main():
    n, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    to = [[None]*n for _ in range(60)]
    to[0] = a
    for i in range(1, 60):
        for j in range(n):
            to[i][j] = to[i-1][to[i-1][j]-1]
    p = 1
    for i in range(59, -1, -1):
        num = 1 << i
        if k >= num:
            k -= num
            p = to[i][p-1]
    print(p)
            

if __name__ == "__main__":
    main()

# Optimized solution
def main():
    n, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    to = [[None]*n for _ in range(60)]
    to[0] = a[:]
    for i in range(1, 60):
        for j in range(n):
            to[i][j] = to[i-1][to[i-1][j]-1]
    p = 1
    for i in range(59, -1, -1):
        num = 1 << i
        if k >= num:
            k -= num
            p = to[i][p-1]
    print(p)
        

if __name__ == "__main__":
    main()
# Original solution
n,k = list(map(int, input().split()))
d={}
l = list(map(int, input().split()))
for i in range(len(l)):
    d[i+1] = l[i]

city = 1
l2 = [1]
while True:
    city = d[city]
    if city in l2:
        break
    l2.append(city)

first = l2.index(city)
if len(l2) <= k:
    if city == l2[-1]:
        print(city)
    else:
        l2 = l2[first:]
        print((l2[(k-first)%(len(l2))]))
else:
    print((l2[k]))

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

journey = [1]

for i in range(2*n):
    next = l[journey[-1]]
    journey.append(next)
if k <= n+1:
    print((journey[k]))
    exit()

end = n
start = n-1

while journey[start] != journey[end]:
    start -= 1

period = end - start
k %= period

while k < n:
    k += period

print((journey[k]))
# Original solution
from collections import deque

def main():
    N,K=list(map(int,input().split()))

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

    loop=[]

    slack_que=deque([])
    flag=0
    t=0
    start=0
    while flag==0:
        slack_que.append(t)
        t=A[t]
        slack_que.append(t)
        ind=slack_que.index(t)
        if (ind!=len(slack_que)-1):
            start=ind
            flag=1
        slack_que.pop()

    slack=list(slack_que)
    slack_num=start
    loop_num=len(slack)-slack_num

    # print(slack)
    # print(start)
    # print(slack_num)
    # print(loop_num)
    #
    loop=slack[start:]
    # print(loop)
    if (K-slack_num)<0:
        res=slack[K]+1
    else:
        tele_num=((K-slack_num)%loop_num)
        town=loop[tele_num]
        res=town+1

    print(res)

if __name__=="__main__":
    main()



# Optimized solution
from collections import deque

def main():
    N,K=list(map(int,input().split()))

    A=list([int(x)-1 for x in input().split()])
    FootPrintA=A[:]

    loop=[]

    slack_que=deque([])
    flag=0
    t=0
    start=0
    while flag==0:
        slack_que.append(t)
        t_ = FootPrintA[t]
        FootPrintA[t]=-1
        if t_==-1:
            start=slack_que.index(t)
            flag=1
            slack_que.pop()
        t = A[t]

    slack=list(slack_que)
    slack_num=start
    loop_num=len(slack)-slack_num

    # print(slack)
    # print(start)
    # print(slack_num)
    # print(loop_num)
    #
    loop=slack[start:]
    # print(loop)
    if (K-slack_num)<0:
        res=slack[K]+1
    else:
        tele_num=((K-slack_num)%loop_num)
        town=loop[tele_num]
        res=town+1

    print(res)

if __name__=="__main__":
    main()
# Original solution

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

loop = []
trace = [0] * (N+1)

ai = 1
for i in range(N+1):
    if ai in trace:
        ind = trace.index(ai)
        loop = trace[ind:i]
        trace = trace[:ind]
        break

    trace[i] = ai # ??
    ai = A_list[ai-1]

if len(trace) > K:
    print((trace[K]))
else:
    ind = K - len(trace)
    ind = ind % len(loop)
    print((loop[ind]))


# Optimized solution

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

loop = []
trace = [0] * (N+1)
visited = set()

ai = 1
for i in range(N+1):
    if ai in visited:
        ind = trace.index(ai)
        loop = trace[ind:i]
        trace = trace[:ind]
        break
    visited.add(ai)
    
    trace[i] = ai # ??
    ai = A_list[ai-1]


if len(trace) > K:
    print((trace[K]))
else:
    ind = K - len(trace)
    ind = ind % len(loop)
    print((loop[ind]))
# Original solution
N, K = list(map(int, input().split()))
A = [0] + list(map(int, input().split()))

now = 1
visited = []
visited_set = set()

for i in range(1, N+1):
    visited.append(now)
    visited_set.add(now)
    now = A[now]
    if now in visited_set:
        loop_start = visited.index(now)
        loop_length = i - loop_start
        break

if K >= loop_start:
    print((visited[loop_start + (K - loop_start) % loop_length]))
else:
    print((visited[K]))


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

now = 1
visited = []
visited_set = set()
flag = False

for i in range(1, K+1):
    visited.append(now)
    visited_set.add(now)
    now = A[now]
    if now in visited_set:
        loop_start = visited.index(now)
        loop_length = i - loop_start
        flag = True
        break
else:
    print(now)

if flag:
    print((visited[loop_start + (K - loop_start) % loop_length]))
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
 
def func1(lst, value):
    return [i for i, x in enumerate(lst) if x == value]
  
temp=1
trace=[1]
circle=[]
for i in range(K):
  temp=A[temp-1]
  ans=func1(trace,temp)
  if len(ans)==1:
    circle.append(i-ans[0]+1)
    #print(circle)
    break
  trace.append(temp)
  #print("temp",temp)
#print((K-i)%len(circle)-1)
if len(circle)!=0:
  amari=(K-i)%circle[0]
  temp=1
  for j in range(i+amari):
    temp=A[temp-1]

print(temp)

# Optimized solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
 
check=[-1 for i in range(N)]
  
temp=1
circle=[]
for i in range(K):
  temp=A[temp-1]
  if check[temp-1]==-1:
    check[temp-1]=i
  else:
    circle.append(i-check[temp-1])
    #print(circle)
    break
  #print("temp",temp)
#print((K-i)%len(circle)-1)
if len(circle)!=0:
  amari=(K-i)%circle[0]
  temp=1
  for j in range(i+amari):
    temp=A[temp-1] 

print(temp)
# Original solution
import sys
readline = sys.stdin.readline

N,K = list(map(int,readline().split()))
A = [0] + list(map(int,readline().split()))

now = 1
while K > 0:
  if K & 1:
    now = A[now]
  A = [A[A[i]] for i in range(len(A))]
  K >>= 1

print(now)

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

N,K = list(map(int,readline().split()))
A = [0] + list(map(int,readline().split()))

pos = 1

while K:
  if K & 1:
    pos = A[pos]
  A = [A[A[i]] for i in range(N + 1)]
  K >>= 1
  
print(pos)