The Kingdom of Takahashi has N towns, numbered 1 through N.
There is one teleporter in each town. The teleporter in Town i (1 \leq i \leq N) sends you to Town A_i.
Takahashi, the king, loves the positive integer K. The selfish king wonders what town he will be in if he starts at Town 1 and uses a teleporter exactly K times from there.
Help the king by writing a program that answers this question.

-----Constraints-----
 - 2 \leq N \leq 2 \times 10^5
 - 1 \leq A_i \leq N
 - 1 \leq K \leq 10^{18}

-----Input-----
Input is given from Standard Input in the following format:
N K
A_1 A_2 \dots A_N

-----Output-----
Print the integer representing the town the king will be in if he starts at Town 1 and uses a teleporter exactly K times from there.

-----Sample Input-----
4 5
3 2 4 1

-----Sample Output-----
4

If we start at Town 1 and use the teleporter 5 times, our travel will be as follows: 1 \to 3 \to 4 \to 1 \to 3 \to 4.

Difficulty: interview

Starter code:

Solutions:
from collections import defaultdict
def main():
    n, k = 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)
'''
def __starting_point():
    main()
__starting_point()

n,k=map(int, input().split())
a=list(map(int, input().split()))
b=[False]*n
pos=0
for i in range(min(n,k)):
    if b[pos]!=False:
        loop=i-b[pos]+1
        break
    b[pos]=i+1
    pos=a[pos]-1
    k-=1
if k>0:
    for i in range(k%loop):
        pos=a[pos]-1
print(pos+1)

#!/usr/bin/env python3
import sys
from itertools import chain


def solve(N: int, K: int, A: "List[int]"):
    M = [-1 for _ in range(N)]
    M[0] = 0
    current = 1
    n = 1
    while n <= K:
        current = A[current - 1]
        if M[current - 1] == -1:  # 一度も通ったことがない
            M[current - 1] = n  # n ステップ目に通った事を記録
        else:
            loop_len = n - M[current - 1]  # ループの長さ
            rest = K - n  # 残り長さ
            rest = rest % loop_len  # 残り長さをループの余剰にする
            K = n + rest
        n += 1
    return current


def main():
    tokens = chain(*(line.split() for line in sys.stdin))
    # N, K, A = map(int, line.split())
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    answer = solve(N, K, A)
    print(answer)


def __starting_point():
    main()

__starting_point()

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

check = [0] * (N+1) #対象の町を訪問するのが初めてか
li = [] #町の移動順
i, j = 1, 1 #現在の町の番号と移動回数

while True:
  k = A[i-1] #移動先の町の番号
  if check[k] == 1:
    #前に訪問したことがある場合
    n = li.index(k)+1 #ループに入った時点での移動回数
    break
  check[k] = 1
  li.append(k)
  i = k
  j += 1

if K < n: print(li[K-1])
else: print(li[(K-n) % (j-n) + n - 1])

#!/usr/bin/env python3

import numpy as np


# def input():
#     return sys.stdin.readline().rstrip()


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

    warps = list(map(int, input().split()))
    warps = [0] + warps
    warps = np.array(warps, dtype=int)

    order_num = np.zeros(len(warps) + 1, dtype=int)
    path_history = []

    node = 1
    while order_num[node] == 0:
        path_history.append(node)
        order_num[node] = len(path_history)
        node = warps[node]

    # print(order_num)
    # print(path_history)
    begin = order_num[node]
    # print(tail)

    if k <= begin:
        print((path_history[k]))
    else:
        # path_history = path_history[tail:]
        # print(path_history)
        leng = len(path_history) - order_num[node] + 1
        # print(leng)
        index = (k - (begin - 1)) % leng
        # print(index)
        print((path_history[begin - 1 + index]))


main()


N, K = map(int, input().split())
A = [0]+list(map(int, input().split()))
B = [-1]*-~N
p = 1
for i in range(K):
    if B[p] >= 0 :break
    B[p] = i
    p = A[p]
else: print(p); return
print(B.index((K-B[p])%(i-B[p])+B[p]))

N,K=map(int,input().split())
A = list(map(int,input().split()))
count = 0
now = 1
city = [1]
city2 = {1}
while count < K:
    count +=  1
    now = A[now-1]
    if now in city2:
        break
    else:
        city.append(now)
        city2.add(now)
if count == K:
    print(now)
else:
    n = city.index(now)
    K -= n
    count -= n
    K %= count
    print(city[n+K])

N,K = map(int,input().split())
A = list(map(lambda x:int(x)-1,input().split()))
i = 0
visited = set([0])

while K > 0:
    i = A[i]
    K -= 1
    if i in visited:
        break
    visited.add(i)
if K == 0:
    print(i+1)
    return
ls = [i]
j = i
while True:
    j = A[j]
    if j == i:
        break
    ls.append(j)
print(ls[K % len(ls)]+1)

n, k = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))
prev = 0
count = 0
used = {prev: count}
for _ in range(min(k, n)):
  prev = A[prev]
  count += 1
  if prev in used:
    for _ in range((k - used[prev]) % (count - used[prev])):
      prev = A[prev]
    break
  used[prev] = count
print(prev + 1)

f=lambda:map(int,input().split())
N,K=f()
*A,=[0]+list(f())
F=[0]*(2*10**5+1)

G=[1]
F[1]=1
i=0
while i<=N:
 n=A[G[-1]]
 if F[n]:break
 F[n]=1
 G.append(n)
 i+=1
t=G.index(A[G[-1]])
if (K<t):
 print(G[K])
else:
 G=G[t:]
 print(G[(K-t)%len(G)]) 

n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
rec = [0]
i = 0
flag = [0 for _ in range(n + 1)]
while True:
    if flag[rec[i]] == 0:
        flag[rec[i]] = 1
        rec.append(a[rec[i]] - 1)
    else:
        start = rec.index(a[rec[i]] - 1)
        loop = rec[start:]
        pre = rec[:start]
        break
    i += 1
count = (k - len(pre)) % len(loop)
if k <= len(pre):
    print((pre[k] + 1))
else:
    print((loop[count] + 1))


#nは街の数　kは移動の回数　k＋１個の街にいくことになる　
#最高でもn回移動すれば一つは二回訪れる街が現れる　そのあとはループする
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))

b = [-1]*(n+1) #街３に5回目の移動でついた場合、b[3]に５が入る　
tmp = [] #経路を記録していく
here = 1
count = 0 #移動回数

while True:
    if b[here] != -1: #一度訪れた街に再び来た
        roop = count - b[here] #ループの長さ　(街aに二回目に来た時の移動回数-一回目に来た時の移動回数)
        if k < count: #ループに入る前に移動が終わった時
            print((tmp[k]))
        else:
            new_tmp = tmp[b[here]:]
            s = k-b[here]
            print((new_tmp[s%roop]))
        break
    b[here] = count
    count += 1
    tmp.append(here)
    here = a[here-1]


import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    n,k = LI()
    a = [None] + LI()
    explored = {1}
    lst = [1]
    lenth = 0
    start = 0
    junkan = []
    now = 1
    while lenth==0:
        nxt = a[now]
        if nxt in explored:
            index = lst.index(nxt)
            junkan = [lst[-1]] + lst[index:-1]
            start = index
            lenth = len(junkan)
        else:
            explored.add(nxt)
            lst.append(nxt)
        now = nxt
    ans = 0
    if k<start:
        ans = lst[k]
    else:
        r = (k-start+1)%lenth
        ans = junkan[r]

    print(ans)


main()            


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

now = 1
path = [1]

for i in range(N + 2):
    now = A[now]
    path.append(now)

if i >= K:
    print(path[K])
    return

now = path.pop()
lo_start = i - 1
while path[lo_start] != now:
    lo_start -= 1

loop = path[lo_start:]

ans = loop[(K - path.index(now)) % len(loop)]

print(ans)

def __starting_point():

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

    B = set()
    cnt = 0
    ind = 1
    startind = 0
    D = []
    while True:
        if A[ind] not in B:
            B.add(ind)
            D.append(ind)
            cnt += 1
            ind = A[ind]
        else:
            B.add(ind)
            D.append(ind)
            cnt += 1
            startind = A[ind]
            break

    C = set()
    ind = startind
    ANS = []
    while True:
        if A[ind] not in C:
            C.add(ind)
            ind = A[ind]
            ANS.append(ind)
        else:
            C.add(ind)
            ANS.append(A[ind])
            break

    if k >= cnt:
        tmp = k - cnt
        tmp = tmp % (len(C))
        print((ANS[tmp-1]))
    else:
        print((D[k]))

__starting_point()

n, K = list(map(int, input().split()))
A = list([int(x) - 1 for x in input().split()])
done = [-1 for _ in range(n)]
tmp = 0
done[0] = 0
for k in range(1, K + 1):
    tmp = A[tmp]
    if done[tmp] >= 0:
        for i in range((K - done[tmp]) % (k - done[tmp])):
            tmp = A[tmp]
        print((tmp + 1))
        return
    else:
        done[tmp] = k
print((tmp + 1))


def __starting_point():
    """
    1 2 3 4 5 6 5
    2 3 4 2 3 4 2
    """
    n,k = list(map(int, input().split()))
    a = list(map(int, input().split()))

    start = 1

    loop_start = 0
    loop_end = 0

    steps = []
    steps_map = {}

    steps.append(start)

    cur = start
    for i in range(n):
        cur = a[cur-1]
        if cur in steps_map:
            loop_start = steps_map[cur] # 1
            loop_end = i+1  # 4
            break
        else:
            steps.append(cur)
            steps_map[cur] = i+1
    
    # print(loop_start, loop_end)
    # print(steps)
    if(k <= loop_start):
        print((steps[k]))
    else:
        temp = (k - loop_start) % (loop_end - loop_start)
        print((steps[temp + loop_start]))



__starting_point()

N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=[0]*(N+1)
B[0]=1;c=0;d=0
if B[0] in A:c=B[0]
for i in range(1,N+1):
  B[i]=A[B[i-1]-1]

d=B.index(B[-1])+1
if K<=N:print((B[K]));return
#if (K+1-d)%(N+1-d)==0:print(B[-1])
print((B[d-1+(K+1-d)%(N+1-d)]))


n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
dic={}
wk=1
start=0
for i in range(1,n+1):
  wk=a[wk-1]
  if wk in dic:
    start=dic[wk]
    break
  dic[wk]=i
end=len(dic)
loopcnt=end-start+1
keys=list(dic.keys())
if k<start:
  print((keys[k-1]))
else:
  chk=(k-start+1)%loopcnt
  if chk==0:
    chk=loopcnt
  print((keys[(start-1)+chk-1]))


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

dic = {}
list_town = []
set_town = set()
town = 1

for i, v in enumerate(A):
    dic[i+1] = v

for _ in range(K):
    list_town.append(town)
    set_town.add(town)
    town = dic[town]
    if town in set_town:
        stop_twon = town
        break

if N <= K:
    list_first_split = list_town[:list_town.index(stop_twon)]
    list_second_split = list_town[list_town.index(stop_twon):]
    print(list_second_split[(K - (len(list_first_split))) % len(list_second_split)])
else:
    print(town)

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

a = [i-1 for i in a]

d = [1]*n
p = 0
b = []
while d[p]:
    b.append(p)
    d[p] = 0
    p = a[p]
avant = b.index(p)
loop_count = len(b) - avant
c = b[avant:]

if k <= avant:
    print((b[k]+1))
else:
    k -= avant
    k %= loop_count
    print((c[k]+1))


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

dist = [0 for i in [0]*(n+1)]
idx = 1
d = 1
while not dist[idx] and d<k+1:
    dist[idx] = d
    idx = a[idx-1]
    d += 1
    #print(dist)
if d==k+1:
    print(idx)
else:
    rem = dist[idx] - 1
    cyc = d - dist[idx]
    k -= rem
    k %= cyc
    for i in range(k):
        idx = a[idx-1]
    print(idx)

n, k = [int(x) for x in input().split()]
a_list = [int(x) - 1 for x in input().split()]
ci = 0
while k:
    if k & 1:
        ci = a_list[ci]
    k >>= 1
    a_list = [a_list[a_list[i]] for i in range(n)]
print(ci + 1)

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

visited = set([1])
cnt = 0
t = [1]
p = 1

while AS[p-1] not in visited and cnt < K:
  a = AS[p-1]
  visited.add(a)
  t.append(a)
  p = a
  cnt += 1

if cnt == K:
  print((t[-1]))
  import sys
  return

f_cnt = t.index(AS[p-1])
loop_cnt = cnt + 1 - f_cnt
print((t[f_cnt+(K-f_cnt)%loop_cnt]))


N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[0]*N
B[0]=1
if B[0] in A:c=B[0]
for i in range(1,N):
  B[i]=A[B[i-1]-1]
 
d=B.index(B[-1])+1
if K<=N:print(B[K]);return
print(B[d-1+(K+1-d)%(N-d)])

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))


import numpy as np

def main():
    N,K = map(int,input().split())
    A = [0]
    A += list(map(int,input().split()))
    A = np.array(A)
    
    i = 1
    pas = np.zeros(N)
    pas[0] = i
    k = 1
    pass_set = set(pas)
    while k <= K:
        if A[i] in pass_set:
            rps = np.where(pas==(A[i]))[0]
            ans = A[i]
            break
        pas[k] = A[i]
        pass_set.add(A[i])
        ans = A[i]
        i = A[i]
        k += 1

    if k >= K:
        print(ans)
    else:
        rpnum = (K-rps[0])%(k-rps)
        print(int(pas[rps[0]+rpnum]))

main()

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

t = 0
count = 0
visited = [0]*n
l_count = 0

for _ in range(k):
    visited[t] += count
    count += 1
    t = a[t]-1

    if visited[t] != 0:
        break

k = (k-count)%(count-visited[t])

for _ in range(k):
    t = a[t] - 1

print((t+1))


N,K=list(map(int,input().split()))
A=[int(x) for x in input().split()]
already=set()
already.add(1)
placelist=[1]
numofmove=0
now=1
loopstart=0
loopend=0
remain=0
while(numofmove<K):
    now=A[now-1]
    #print(now)
    numofmove+=1
    placelist.append(now)
    if now in already:
        loopstart=placelist.index(now)
        loopend=numofmove
        #print(remain,numofmove,loopstart,loopend,placelist)
        remain=(K-numofmove)%(loopend-loopstart)
        for i in range(remain):
            now=A[now-1]
        break 
    else:
        already.add(now)
print(now)


#!/usr/bin/env python3

import sys
import numpy as np


# def input():
#     return sys.stdin.readline().rstrip()


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

    # warps = list(map(int, sys.stdin.buffer.readline().split()))
    warps = list(map(int, input().split()))
    warps = [0] + warps
    warps = np.array(warps, dtype=int)

    dp = np.zeros((k.bit_length() + 1, n + 1), dtype=int)

    dp[0, :] = warps

    for h in range(1, len(dp)):
        dp[h] = dp[h - 1][dp[h - 1]]

    node = 1
    # for i in reversed(range(k.bit_length())):
    for i in range(k.bit_length(), -1, -1):
        if k >> i & 1:
            node = dp[i][node]

    print(node)


main()


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

tele = [1]
went = set(tele)
now = 1
cnt = 0
flag = True

for i in range(k):
  now = a[now-1]
  if i != k-1 and now in went:
    tele = tele[tele.index(now):]
    cnt = i+1
    flag = False
    break
  tele.append(now)
  went.add(now)

if flag == True:
  print(tele[-1])

else:
  k -= cnt
  cnt = k % len(tele)
  print(tele[cnt])

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

now = 1

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

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

ci = 0
temp_dict = {0: 0}
temp_list = [0]
for i in range(1, k + 1):
    temp = a_list[ci]
    if temp in temp_dict:
        ci = temp_list[(k - i) % (i - temp_dict[temp]) + temp_dict[temp]]
        break
    temp_dict[temp] = i
    temp_list.append(temp)
    ci = temp
print(ci + 1)

N,K=map(int,input().split())
A=list(map(int,input().split()))
B=[0]*N
point=1
m,l=0,0
if K>N:
    for i in range(N):
        if B[point-1]==0:
            B[point-1]=i+1
            point=A[point-1]
        else:
            m=i+1-B[point-1]
            l=B[point-1]
            break
    if m!=0:
        m=(K-l)%m
    else:
        m=N
else:
    m=K
ans=1
for i in range(l+m):
    ans=A[ans-1]
 
print(ans)

def main():
    N,K = map(int,input().split())
    A = [0] + list(map(int,input().split()))
    
    i = 1
    pas = [i]
    pas_set = set(pas)
    k = 1
    while k <= K:
        if A[i] in pas_set:
            rps = pas.index(A[i])
            ans = A[i]
            break
        pas.append(A[i])
        pas_set.add(A[i])
        ans = A[i]
        i = A[i]
        k += 1

    if k >= K:
        print(ans)
    else:
        rpnum = (K-rps)%(k-rps)
        print(pas[rps+rpnum])

main()

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

visited = [0 for _ in range(N)]
first_visit = [0 for _ in range(N)]

now = 0
flag = True
for i in range(10 ** 5 * 5):
    if first_visit[now] == 0:
        first_visit[now] = i

    visited[A[now] - 1] += 1
    now = A[now] - 1

    if i == K - 1:
        print((now + 1))
        flag = False
        break

if flag:
    num = 0
    for i in range(N):
        if visited[i] > 2:
            num += 1

    for i in range(N):
        if visited[i] >= 2:
            if K % num == first_visit[i] % num:
                print((i + 1))
                break


N, K = map(int, input().split())
A = list(map(int, input().split()))
B = [1]
C = [1] + [0] * (N - 1)
i = 0

while C[A[i] - 1] == 0:
    B.append(A[i])
    C[A[i] - 1] = 1
    i = A[i] - 1

ans = 0
for j in range(len(B)):
    if B[j] == A[i]:
        ans += j

if (len(B) - ans != 0) and (K - ans > 0):
    ans += (K - ans) % (len(B) - ans)
elif K - ans <= 0:
    ans = K


print(B[ans])

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

visited = [0] * (1 + n)
curr = 1
while k:
    if visited[curr]:
        break
    else:
        visited[curr] = k
        curr = a[curr]
        k -= 1
        if k == 0:
            print(curr)
            return
repeat = visited[curr] - k
k = k % repeat
while k:
    curr = a[curr]
    k -= 1
print(curr)

from copy import deepcopy

def main():
    n, k = map(int, input().split())
    a = [int(x)-1 for x in input().split()]
    visited = set()
    i = 0
    cnt = 0
    # 途中で前に行ったところに行ったら終わり
    # kが小さくてcnt == kになってもおわり
    while True:
        if i in visited:
            break
        visited.add(i)
        cnt += 1
        i = a[i]
        if cnt == k:
            print(i+1)
            return
    k -= cnt
    period = list()
    period.append(i)
    i = a[i]
    # 何回で同じ場所に戻るか
    while True:
        if i == period[0]:
            break
        period.append(i)
        i = a[i]
    # 余り
    mod = k % len(period)
    ans = period[mod]
    print(ans+1)

def __starting_point():
    main()
__starting_point()

n,k = list(map(int,input().split()))
button = list(map(int,input().split()))
visit = [-1]*n
hisitory = [-1]
push = 0
f = 0

for i in range(k):
    visit[push] = i+1
    hisitory.append(push)
    push = button[push] -1
    if(visit[push] != -1):  
        f = 1
        start = visit[push]
        last=push
        end = i+1
        break
if(f == 0):
    print((button[hisitory[-1]]))
else:
    geta = start -1
    loopk = k - geta
    loop = end -start + 1
    modk = loopk%loop
    if(modk == 0):
        modk = loop
    print((button[hisitory[geta + modk]]))
    # print(hisitory)
    # print(geta,modk,loop)


N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=[0]*N
B[0]=1
if B[0] in A:c=B[0]
for i in range(1,N):
  B[i]=A[B[i-1]-1]

d=B.index(B[-1])+1
if K<=N:print((B[K]));return
print((B[d-1+(K+1-d)%(N-d)]))


N, K = map(int, input().split())
A = list(map(int, input().split()))
pos = 0
res = [-1] * 3*10**5
d = 0
way = []
l = 0
c = 0

for i in range(N) :
    A[i] -= 1
    
for i in range(K+1):
    if(res[pos] != -1) :
        l = d - res[pos]
        c = d - l
        res[pos] = d
        break
    res[pos] = d
    way.append(pos)
    d += 1
    pos = A[pos]

ans = 0
if(K+1 <= len(way)) :
    ans = way[K]
else :
    K -= c
    K = K%l
    ans = way[K + c]
print(ans+1)

N,K=[int(s) for s in input().split()]
ls=[int(s) for s in input().split()]
town=set()
town.add(1)
town_ls=[1]
now=1
for i in range(min([K,N])):
  now=ls[now-1]
  if now in town:
    break
  town.add(now)
  town_ls.append(now)

if i+1==K:
  print(now)
else:
  L=i+1
  S=town_ls.index(now)
  loop=L-S
  #print(loop,S)
  x=(K-S)%loop+S
  print(town_ls[x])

n, k = map(int, input().split())
a = list(map(int, input().split()))
d = {}
for i in range(1, n+1):
    d[i] = 0
l = [1]
x = 1
if n >= k:
    for i in range(k):
        x = a[x-1]
    print(x)
    return
for i in range(n):
    x = a[x-1]
    if d[x] == 1:
        k -= l.index(x)
        print(l[l.index(x):][k%(l.index(x)-len(l))])
        return
    l.append(x)
    d[x] += 1
print(x)

f=lambda:map(int,input().split())
N,K=f()
*A,=list(f())
F=[-1]*(2*10**5+1)

G=[]
n=1
while F[n]==-1:
 F[n]=len(G)
 G.append(n)
 n=A[n-1]
t=len(G)-F[n]
l=F[n]
if (l<=K):
 K-=l
 K%=t
 K+=l
print(G[K]) 

import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
import numpy as np
def main():
    n, k, *a = map(int, read().split())

    cur = 1
    path = [0] * (n + 1)
    while k:
        if path[cur]:
            break
        else:
            path[cur] = k
            cur = a[cur - 1]
            k -= 1
            if k == 0:
                print(cur)
                return
    cycle = path[cur] - k
    k = k % cycle
    while k:
        cur = a[cur - 1]
        k -= 1
    print(cur)

def __starting_point():
    main()
__starting_point()

from collections import deque

def solve(A, K):
    a = deque() # 繰り返し部分
    seen = [False for _ in range(len(A))] # 一度見たかどうか
    cur = 0
    while True:
        # 一度通った頂点を見つけたときの処理
        if seen[cur]:
            while a[0] != cur:
                # 最初の余計な数手分を除去する
                K -= 1
                a.popleft()

                # K が限界になったらリターン
                if K == 0:
                    return a[0] + 1
            break

        # 最初は愚直にシミュレーションしつつ、履歴をメモしていく
        a.append(cur)
        seen[cur] = True
        cur = A[cur]        
    return a[K % len(a)] + 1

N, K = map(int, input().split())
A = list(map(int, input().split()))
A = [v - 1 for v in A]
print(solve(A, K))

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

dic = {}
list_town = []
set_town = set()
town = 1

for i, v in enumerate(A):
    dic[i+1] = v

for _ in range(K):
    list_town.append(town)
    set_town.add(town)
    town = dic[town]
    if town in set_town:
        stop_town = town
        break

if N <= K:
    list_first_split = list_town[:list_town.index(stop_town)]
    list_second_split = list_town[list_town.index(stop_town):]
    print(list_second_split[(K - (len(list_first_split))) % len(list_second_split)])
else:
    print(town)

from collections import defaultdict

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

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

visited = [0] * N

current = 0
i = 1
while i <= K:
    current = A[current] - 1
    if visited[current] == 0:
        visited[current] = i
    else:
        loop = i - visited[current]
        num_loop = (K - i) // loop
        i += loop * num_loop

    i += 1

ans = current + 1
print(ans)

N, K = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))

done = [-1]*N
done[0] = 0

tmp = 0
done[0] = 0
for k in range(1, K + 1):
    tmp = A[tmp]
    if done[tmp] >= 0:
        for _ in range((K - done[tmp]) % (k - done[tmp])):
            tmp = A[tmp]
        print(tmp + 1)
        return
    else:
        done[tmp] = k
print(tmp + 1)

N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
check = [0]*N
ima = 0

for i in range(K):
  if check[A[ima]-1] != 0:
    loopen = ima
    check[ima] = i+1
    looplen = check[ima] - check[A[ima]-1] + 1
    loopend = i
    break
  if i == K-1:
    print((A[ima]))
    return
  check[ima] = i+1
  ima = A[ima]-1

offset = (K-(i-looplen)-1)%looplen
ima = 0
for i in range(loopend-looplen+offset+1):
  ima = A[ima]-1
print((ima+1))


n, k = map(int, input().split())
a = list(map(int, input().split()))
p = 1
t = [1]
u = set()
u.add(1)
for i in range(n):
  p = a[p - 1]
  if p not in u:
    t.append(p)
    u.add(p)
  else:
    break
c = t.index(p)
r = len(t) - c
if k < len(t):
  ans = t[k]
else:
  if (k - c + 1) % r == 0:
    ans = t[-1]
  else:
    ans = t[(k - c + 1) % r + c - 1]
print(ans)

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

f = [0]*n
c = 1
for i in range(k):
    if f[a]:
        k %= c-f[a]
        for i in range(k):
            a = b[a]
        print(a+1)
        break
    f[a] = c
    k -= 1
    c += 1
    a = b[a]
else:
    print(a+1)


url = "https://atcoder.jp/contests/abc162/tasks/abc162_d"
import itertools


def main():
    n, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    route = []
    istuka = [0] * (n+1)
    next = 1
    # 同じ街に訪れるまでループ
    for _ in range(k):
        if istuka[next] == 1:
            break
        else:
            istuka[next] = 1
            route.append(next)
        next = a[next - 1]
    if n >= k:
        print(next)
        return
    ans = route[route.index(next):]
    idx = (k - route.index(next)) % len(ans)
    print(ans[idx])



def __starting_point():
    main()
__starting_point()

def main():
    n,k=map(int,input().split())
    a=[int(i)-1 for i in input().split()]
    visit=[False]*n
    visit[0]=True
    loop, loopstart, loopout, cur=0, -1, False, 0
    i = 0
    while i < k:
        #print("{}->{}".format(cur+1, a[cur]+1))
        cur=a[cur]
        if not loopout and visit[cur]:
            #print("OnLoop", k)
            if loopstart == cur:
                k=(k-sum(visit))%loop
                loopout=True
                #print("OutLoop", k)
                i = 0
                continue
            elif loopstart == -1:
                #print("loop start with", cur+1)
                loopstart = cur
            loop+=1
        else:
            visit[cur]=True
        i += 1
    print(cur+1)
    
def __starting_point():
    main()
__starting_point()

import sys
from collections import deque, defaultdict, Counter
from itertools import accumulate, product, permutations, combinations
from operator import itemgetter
from bisect import bisect_left, bisect_right
from heapq import heappop, heappush
from math import ceil, floor, sqrt, gcd, inf
from copy import deepcopy
import numpy as np
import scipy as sp

INF = inf
MOD = 1000000007

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

tmp = [0 for i in range(n + 1)]
cnt = 0
res = 1

while cnt < k:
    cnt += 1
    if tmp[res] == 0:
        tmp[res] = cnt
    else:
        cnt += (k - cnt) // (cnt - tmp[res]) * (cnt - tmp[res])
        tmp[res] = cnt
    res = A[res - 1]

print(res)


N,K=map(int,input().split())
A=list(map(int,input().split()))
 
count=[-1]*(N+1) #その点へ最初に到達した回
pos=1 #現在地
num=0 #試行回数
while count[pos]==-1:
    count[pos]=num
    pos=A[pos-1]
    num+=1
    
loop=max(count)-count[pos]+1
 
if num>K:
        print(count.index(K))
elif loop==1 and num<=K:
    print(count.index(max(count)))
else:
    start= num-loop
    ans=(K-num)%loop
    print(count.index(start+ans))

n, k = map(int,input().split())
a = list(map(int,input().split()))
l = [0]*n
i=0
cnt=0
while l[i]==0:
    l[i] = a[i]
    i = a[i]-1 
    cnt += 1
start = i+1
i = 0
pre = 0
while i+1!=start:
    i = a[i]-1
    pre += 1
loop = cnt-pre
if pre+loop<k:
    k=(k-pre)%loop+pre
i = 0
for _ in range(k):
    i = a[i]-1
print(i+1)

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

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

ord = [-1 for _ in range(N)]
ord[0] = 0
v = A[0]-1
root = [0]

while ord[v] == -1:
    #ordに何回目のワープかが記録される
    ord[v] = len(root)
        #ワープの軌跡を記録
    root.append(v)

    #次の地点にワープ5
    v = A[v]-1

# print(ord)
# print(root)

#ord[v]:最終地点（ループ起点 or ループ前の道のり）
# ループ起点までの余分な手
l = ord[v]
#ループ距離
c = len(root) - l

if K < l:
    #ループ前にワープが終了した場合、最終地点を出力
    ans = root[K]
else:
    #ループする回数を計算
    # はじめにループ起点までの余分手をKから引く
    K -= l
    # ループのmodを計算
    K %= c
    # 余分手＋ループのmodの位置の国に止まる
    ans = root[l+K]
print((ans+1))



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)))
    return
print(now)


N,K = map(int,input().split())
A = list(map(int,input().split()))
G = [1]

for n in range(N-1):
  G.append(A[G[n]-1])

if len(G)<K:
  a = G.index(G[-1])
  b = len(G)-a-1
  K = (K-a)%b+a

print(G[K])

def main():
    n, k = map(int, input().split())
    inlis = list(map(int, input().split()))
    flag = 0
    trans = 0
    now = 1
    indic = dict()
    indic[1] = 0

    while flag < 1:
        if trans < k:
            trans += 1
            tsugi = inlis[now-1]
            now = tsugi
            if tsugi not in indic:
                indic[tsugi] = trans
                #print(tsugi, indic)
            else:
                flag = 1
                loop = trans - indic[tsugi]
                yokei = indic[tsugi]
                #print(loop, yokei)

        if trans == k:
            print(tsugi)
            return
    
    loopamari = (k-yokei) % loop

    for _ in range(loopamari):
        tsugi = inlis[now-1]
        now = tsugi
    
    print(now)
    




def __starting_point():
    main()
__starting_point()

from collections import defaultdict

N,K = map(int, input().split())
A = [int(i) for i in input().split()]
used_dict = defaultdict(int)
used_dict[0] += 1
now_town = 0
flag = False

for i in range(min(N,K)):
    now_town = A[now_town]-1
    if used_dict[now_town]:
        used_dict[now_town] += 1
        break
    used_dict[now_town] += 1
else:
    flag = True

if not flag:
    now_town2 = 0
    cnt = 0
    while 1:
        if now_town2 == now_town:
            for _ in range((K-cnt)%(i-cnt+1)):
                now_town = A[now_town]-1
            break
        now_town2 = A[now_town2]-1
        cnt += 1
print(now_town+1)

N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=[0]*(N+1)
B[0]=1
if B[0] in A:c=B[0]
for i in range(1,N+1):
  B[i]=A[B[i-1]-1]

d=B.index(B[-1])+1
if K<=N:print((B[K]));return
print((B[d-1+(K+1-d)%(N+1-d)]))


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

dic = {}
for i, v in enumerate(A):
    dic[i+1] = v

town = 1
s = set()
l = []
for _ in range(K):
    l.append(town)
    s.add(town)
    town = dic[town]
    if town in s:
        stop_twon = town
        break
if N <= K:
    list_first_split = l[:l.index(stop_twon)]
    list_second_split = l[l.index(stop_twon):]
    print(list_second_split[(K - (len(list_first_split))) % len(list_second_split)])
else:
    print(town)

n,k=map(int,input().split())
a=list(map(int,input().split()))
b=[0]*(n+1)
count=0
now=1
f=1
for _ in range(k):
    if b[now]:
        f=0
        break
    count+=1
    b[now]=count
    now=a[now-1]
if f:
    print(now)
    return
x=count-b[now]+1
y=(k-b[now]+1)%x
for i in range(y):
    now=a[now-1]
print(now)

#!/usr/bin/env python3

#import
#import math
#import numpy as np
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
A = [a - 1 for a in A]

town = [-1] * N

move = 0
now = 0
while move < K:
    town[now] = move
    now = A[now]
    move += 1 
    if town[now] != -1:
        break

cnt = (K - move) % (move - town[now])

for i in range(cnt):
    now = A[now]

print((now + 1))


N,K=map(int,input().split())
Alist=list(map(int,input().split()))
already=[1]
alreadyset={1}
last=1
while True:
    if Alist[last-1] in alreadyset:
        start=already.index(Alist[last-1])
        break
    already.append(Alist[last-1])
    alreadyset.add(Alist[last-1])
    last=Alist[last-1]
roop=len(already)-start
if K-len(already)<0:
    print(already[K])
else:
    index=(K-start)%roop+start
    while not start<=index<len(already):
        index=index%roop+start
    print(already[index])

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

def index_multi(l, x):
    return [i for i, _x in enumerate(l) if _x == x]

t = 0
lis = [1]
count = [0] + [-1] * (n - 1) #到達回数
for i in range(2 * (10 ** 5) + 1):
    lis.append(a[t])
    t = a[t] - 1
    count[t] += 1
#print(lis)
#print(count)
l_start_number = 0
for i in range(n):
    if count[i] > 0:
        l_start_number = i + 1
        break

l_start = index_multi(lis, l_start_number)[0]
l_goal = index_multi(lis, l_start_number)[1] - 1

loop_lis = []
for i in range(l_start, l_goal + 1):
    loop_lis.append(lis[i])
#print(loop_lis)

loop = len(loop_lis)
if k >= l_start:
    count = (k - l_start) % loop
    print((loop_lis[count]))
else:
    print((lis[k]))


from sys import stdin
nii=lambda:map(int,stdin.readline().split())
lnii=lambda:list(map(int,stdin.readline().split()))

n,k=nii()
a=lnii()

x=0
x_list=[1]
x_table=[0 for i in range(n+1)]
x_table[1]=1

for i in range(k):
  nx=a[x]

  if x_table[nx]!=0:
    inx=x_list.index(nx)
    loop=x_list[inx:]
    zan=k-i

    q=zan%len(loop)

    nx=loop[q-1]
    break

  else:
    x=nx-1
    x_list.append(nx)
    x_table[nx]+=1

print(nx)

N,K=list(map(int,input().split()))
A=list(map(int,input().split()))
B=[0]*(N+1)
B[0]=1;c=0;d=0
if B[0] in A:c=B[0]
for i in range(1,N+1):
  B[i]=A[B[i-1]-1]
#  if c==B[i]:break
#  if A.count(B[i])>1 and d==0:c=B[i];d+=1

d=B.index(B[-1])+1
#print(B.index(B[N-1]))

#print(B,d)
#print(d+1+(K-d-1)%(N-d-1))
#print(B[K],K,d,(K+1-d),(N+1-d))
if K<=N:print((B[K]));return
if (K+1-d)%(N+1-d)==0:print((B[-1]))
else:print((B[d-1+(K+1-d)%(N+1-d)]))
#print(B[d+1+(K-d-1)%(N-d-1)]-1)


from collections import defaultdict
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)

def __starting_point():
    main()
__starting_point()

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

t = 0
count = 0
visited = [0]*n
l_count = 0

for _ in range(k):
    visited[t] += count
    count += 1
    t = a[t]-1

    if visited[t] != 0:
        break

k = (k-count)%(count-visited[t])

for _ in range(k):
    t = a[t] - 1

print(t+1)

from collections import deque
import sys
n,k = map(int, input().split())
A = list(map(int, input().split()))
A = list(map(lambda x:x-1, A))
seen = [0]*n
li = deque()
pos = 0
while True:
    if seen[pos]:
        while li[0]!=pos:
            li.popleft()
            k-=1
            if k==0:
                print(li[0]+1)
                return
        break
    li.append(pos)
    seen[pos] = 1
    pos = A[pos]

print(li[k%len(li)]+1)

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

now = 1
route = []
dic = {}
cnt = 0
entry = []
loop = []

while True:
  cnt += 1
  now = A[now]
  route.append(now)
  if now in dic:
    entry = route[:dic[now]]
    loop = route[dic[now]:]
    break
  dic[now] = cnt

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

from collections import defaultdict
N,K = list(map(int,input().split()))
N_List = list(map(int,input().split()))

N_Dict = defaultdict(int)
N_Dict[1] = 1
Pos = N_List[0]
for i in range(N):
    N_Dict[Pos] += 1
    if N_Dict[Pos] == 2:
        break
    else:
        Pos = N_List[Pos - 1]

##ループ始点がPosに入っている状態
##ループがどのくらいの長さか知りたい
CPos = Pos
flg = 0
Loop_List = [CPos]
while flg == 0:
    CPos = N_List[CPos-1]
    if CPos != Pos:
        Loop_List.append(CPos)
    else:
        flg = 1

##ループの始点に至るまでの長さを求める
FL = len(N_Dict) - len(Loop_List) 
if FL <= K:
    ans = Loop_List[(K - FL) % len(Loop_List)]
else:
    ans =list(N_Dict.keys())[K]
print(ans)


#!/usr/bin/env python3

import sys
import numpy as np


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


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

    # warps = list(map(int, sys.stdin.buffer.readline().split()))
    warps = list(map(int, input().split()))
    warps = [0] + warps
    warps = np.array(warps, dtype=int)

    dp = np.zeros((k.bit_length() + 1, n + 1), dtype=int)

    dp[0, :] = warps

    for h in range(1, len(dp)):
        dp[h] = dp[h - 1][dp[h - 1]]

    node = 1
    # for i in reversed(range(k.bit_length())):
    for i in range(k.bit_length(), -1, -1):
        if k >> i & 1:
            node = dp[i][node]

    print(node)


main()


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

cnts = [None] * N

pos = 0
cnt = 0

while cnt < K:
    if cnts[pos] != None:
        loop_size = cnt - cnts[pos]
        cnt += ((K-cnt-1) // loop_size) * loop_size
        cnts = [None] * N
    cnts[pos] = cnt
    pos = A[pos]
    cnt += 1

print((pos+1))



f=lambda:map(int,input().split())
N,K=f()
*A,=list(f())
 
F=[-1]*(2*10**5+1)
G=[] 
i=1
while F[i]==-1:
    F[i]=len(G)
    G.append(i)
    i=A[i-1]
t=F[i]
if (K<t):
    print(G[K])
else:
    G=G[t:]
    print(G[(K-t)%len(G)]) 

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

count = 0

stack = set()
visited = []
visited_set = set()
endf = False

current = 0
while True:
    i = A[current]-1
    visited_set.add(current)
    visited.append(current)

    if not i in visited_set:
        current = i
        count += 1
    else:
        leng = len(visited_set)
        roop_len = leng - visited.index(i)
        header_len = leng - roop_len
        break

    if count >= K:
        endf = True
        print(i+1)
        break

if not endf:
    roop_ind = (K - header_len + 1) % roop_len
    if roop_ind == 0:
        print(visited[-1]+1)
    else:
        print(visited[header_len + roop_ind-1]+1)

N,K = map(int,input().split())
lsA = [0]+list(map(int,input().split()))
ls = []
set1 = set()
a = 1
for i in range(N+1):
    if a in set1:
        loop = ls[ls.index(a):]
        lenloop = len(loop)
        startls = ls[:ls.index(a)]
        break
    ls.append(a)
    set1.add(a)
    a = lsA[a]
if K < len(startls):
    ans = startls[K]
else:
    ans = loop[(K-len(startls))%lenloop]
print(ans)

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

visited = [0] * (1 + n)
curr = 1
while k:
    if visited[curr]:
        break
    else:
        visited[curr] = k
        curr = a[curr]
        k -= 1
        if k == 0:
            print(curr)
            return
repeat = visited[curr] - k
k = k % repeat
while k:
    curr = a[curr]
    k -= 1
print(curr)

n, k = map(int, input().split())
A = list(map(lambda x: int(x) - 1, input().split()))
prev = 0
count = 0
used = {prev: count}
for _ in range(min(k, n)):
  prev = A[prev]
  count += 1
  if prev in used:
    break
  used[prev] = count
if count > used[prev]:
  for _ in range((k - used[prev]) % (count - used[prev])):
    prev = A[prev]
print(prev + 1)

N,K = map(int,input().split())
A = list(map(int,input().split()))
c = 0
List = []
check = [-1]*N
tmp = 1
for i in range(min(N+1,K)):
    tmp2 = A[tmp-1]
    List.append(tmp2)
    if(check[tmp2-1] >= 0):
        tmp3 = check[tmp2-1]
        del List[-1]
        break
    else:
        check[tmp2-1] = i
        tmp = tmp2
        c += 1
if(c >= K):
    print(List[K-1])
else:
    List2 = List[tmp3:]
    if(c == len(List2)):
        print(List2[(K%len(List2))-1])
    else:
        K -= c
        print(List2[(K%len(List2))-1])

n,k = map(int,input().split())
a = list(map(int,input().split()))
a = list(map(lambda x: x-1,a))
    
visited = [-1] * n
now = 0

for i in range(k):
    if visited[now] != -1:#訪れたことがあるか
        loop = i - visited[now]   #ループの大きさ
        k = (k-(i-loop)) % loop
        
        for _ in range(k):
            now = a[now]
        
        break
        
    visited[now] = i
    now = a[now] 
        
print(now + 1)

f=lambda:map(int,input().split())
N,K=f()
*A,=list(f())
 
F=[-1]*(2*10**5+1)
G=[] 
i=1
while F[i]==-1:
    F[i]=1
    G.append(i)
    i=A[i-1]
t=G.index(A[G[-1]-1])
if (K<t):
    print(G[K])
else:
    G=G[t:]
    print(G[(K-t)%len(G)]) 

f=lambda:map(int,input().split())
N,K=f()
*A,=[0]+list(f())
F=[0]*(2*10**5+1)

G=[1]
F[1]=1
i=0
while i<=N:
 n=A[G[-1]]
 if F[n]:break
 F[n]=1
 G.append(n)
 i+=1
t=G.index(A[G[-1]])
if (t<=K):
 G=G[t:]
 K=(K-t)%len(G)
print(G[K]) 

f=lambda:map(int,input().split())
N,K=f()
*A,=list(f())
 
F=[0]*(2*10**5+1)
 
G=[1]
F[1]=1
i=0
while i<=N:
    new=A[G[-1]-1]
    if F[new]==1:break
    F[new]=1
    G.append(new)
    i+=1
t=G.index(A[G[-1]-1])
if (K<t):
    print(G[K])
else:
    G=G[t:]
    print(G[(K-t)%len(G)]) 

#!/usr/bin/env python3

import numpy as np


# def input():
#     return sys.stdin.readline().rstrip()


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

    warps = list(map(int, input().split()))
    warps = [0] + warps
    warps = np.array(warps, dtype=int)

    dp = np.zeros((k.bit_length() + 1, n + 1), dtype=int)

    dp[0, :] = warps

    for h in range(1, len(dp)):
        # dp[h] = dp[h - 1][dp[h - 1]]
        dp[h] = np.take(dp[h - 1], dp[h - 1])

    node = 1
    # for i in reversed(range(k.bit_length())):
    for i in range(k.bit_length(), -1, -1):
        if k >> i & 1:
            node = dp[i][node]

    print(node)


main()


f=lambda:map(int,input().split())
N,K=f()
*A,=[0]+list(f())

F=[0]*(2*10**5+1)

G=[1]
F[1]=1
i=0
while i<=N:
    new=A[G[-1]]
    if F[new]==1:break
    F[new]=1
    G.append(new)
    i+=1
#print(G,A[G[-1]],G.index(A[G[-1]]))
t=G.index(A[G[-1]])
if (K<t):
    print(G[K])
else:
    G=G[t:]
    print(G[(K-t)%len(G)]) 

n,k=list(map(int,input().split()))
a=list(map(int,input().split()))
dic={}
wk=1
start=0
for i in range(1,n+1):
  wk=a[wk-1]
  if wk in dic:
    start=dic[wk]
    break
  dic[wk]=i
end=len(dic)
loopcnt=end-start+1
keys=list(dic.keys())
if k<start:
  print((keys[k-1]))
else:
  chk=(k-start+1)%loopcnt
  if chk==0:
    chk=loopcnt
  print((keys[(start-1)+chk-1]))


#入力:N,M(int:整数)
def input2():
	return map(int,input().split())

#入力:[n1,n2,...nk](int:整数配列)
def input_array():
	return list(map(int,input().split()))
  
n,k=input2()
A=input_array()

# ある地点から循環に陥る
judge=[True]*n
tmps=[1] #循環手前
count=0 #参照地点

for i in range(2*(10**5)+1):
	if judge[count]==True:
		judge[count]=False
		count=A[count]-1
		tmps.append(count+1)
	else:
		break

loop_st=tmps.index(tmps[-1])
loops=tmps[loop_st:-1]


if k<loop_st:
	print(tmps[k])
else:
	k=k-loop_st
	k%=len(loops)
	print(loops[k])

#!/usr/bin/env python3

import numpy as np


# def input():
#     return sys.stdin.readline().rstrip()


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

    warps = list(map(int, input().split()))
    warps = [0] + warps
    # warps = np.array(warps, dtype=int)

    # order_num = np.zeros(len(warps) + 1, dtype=int)
    order_num = [0 for i in range(len(warps))]
    path_history = []

    node = 1
    while order_num[node] == 0:
        path_history.append(node)
        order_num[node] = len(path_history)
        node = warps[node]

    # print(order_num)
    # print(path_history)
    begin = order_num[node]
    # print(tail)

    if k <= begin:
        print((path_history[k]))
    else:
        # path_history = path_history[tail:]
        # print(path_history)
        leng = len(path_history) - order_num[node] + 1
        # print(leng)
        index = (k - (begin - 1)) % leng
        # print(index)
        print((path_history[begin - 1 + index]))


main()


def delete_head_zeros(n):
	n = str(n)
	l = len(n)
	if "." in n:
		l = n.find(".")
	head_zeros = 0
	for i in range(l - 1):
		if n[i] == "0":
			head_zeros += 1
		else:
			break

	return n[head_zeros:]

# compare a, b
# a, b: int or string
def bigint_compare(a, b):
	a = delete_head_zeros(a)
	b = delete_head_zeros(b)
	if len(a) > len(b):
		return 1
	elif len(a) < len(b):
		return -1
	else:
		if a > b:
			return 1
		elif a < b:
			return -1
		else:
			return 0

# calculate a + b
# a, b: int or string
def bigint_plus(a, b):
	a = str(a)
	b = str(b)

	d = max([len(a), len(b)])
	a = '0' * (d - len(a)) + a
	b = '0' * (d - len(b)) + b

	ans = ""
	carry = 0
	for i in range(d):
		s = int(a[-i-1]) + int(b[-i-1]) + carry
		carry = s // 10
		ans = str(s % 10) + ans
	else:
		if carry:
			ans = str(carry) + ans

	return ans

# calculate a - b
# a, b: int or string
def bigint_minus(a, b): 
	a = str(a)
	b = str(b)
	M = []
	m = []
	sign = ""

	if len(a) > len(b) or (len(a) == len(b) and a >= b):
		[M, m] = [a, b]
	else:
		[M, m] = [b, a]
		sign = "-"
	m = '0' * (len(M) - len(m)) + m

	ans = ""
	borrow = 0
	for i in range(len(M)):
		s = int(M[-i-1]) - int(m[-i-1]) - borrow
		if s < 0:
			borrow = 1
			s += 10
		else:
			borrow = 0
		ans = str(s) + ans

	return sign + delete_head_zeros(ans)

# calculate a * b
# a, b: int or string
def bigint_multiply(a, b):
	a = str(a)
	b = str(b)

	md = []
	for j in range(len(b)):
		carry = 0
		mj = ""
		for i in range(len(a)):
			m = int(a[-i-1]) * int(b[-j-1]) + carry
			carry = m // 10
			mj = str(m % 10) + mj
		else:
			if carry:
				mj = str(carry) + mj
		md.append(mj)

	ans = 0
	for k in range(len(md)):
		ans = bigint_plus(md[k] + "0" * k, ans)

	return ans


# calculate a / b to d digits after decimal point
# a, b, d: int or string
def bigint_divide(a, b, d = 0):
	a = str(a)
	b = str(b)
	d = int(d)
	if d < 0:
		d = 0

	ans = ""
	r = ""
	for i in range(len(a) + d):
		q = 0
		if i < len(a):
			r += a[i]
		elif i == len(a):
			ans += "."
			r += "0"
		else:
			r += "0"

		if bigint_compare(r, b) == -1:
			ans += str(q)
		else:
			while bigint_compare(r, b) >= 0:
				r = bigint_minus(r, b)
				q += 1
			ans += str(q)

	return delete_head_zeros(ans)

def main():
	N, K = input().split(" ")
	A = [int(a) - 1 for a in input().split(" ")]
	visited = [0] * int(N)
	towns = []
	now = 0
	while visited[now] == 0:
		towns.append(now)
		visited[now] = 1
		now = A[now]
	else:
		loop_begin_idx = towns.index(now)
		loop_end_idx = len(towns) - 1
		loop_n = loop_end_idx - loop_begin_idx + 1
	if int(K) < len(towns):
		print((towns[int(K)] + 1))
		return 0
	K_from_loop = bigint_minus(K, loop_begin_idx)
	q = bigint_divide(K_from_loop, loop_n)
	r = bigint_minus(K_from_loop, bigint_multiply(loop_n, q))
	print((towns[loop_begin_idx + int(r)] + 1))

main()


# -*- coding: utf-8 -*-
"""
Created on Mon Sep  7 18:05:47 2020

@author: liang
"""

N, K = map(int, input().split())
A = [int(x) for x in input().split()]
visited = [-1]*N
loop = list()

cur = 1
cnt = 0
while visited[cur-1] == -1:
#while True:
    visited[cur-1] = cnt
    loop.append(cur)
    cnt += 1
    cur = A[cur-1]
    if cnt == K:
        print(cur)
        #print(loop)
        break
else:
    #print(loop)
    loop = loop[visited[cur-1]:]
    T = cnt -visited[cur-1]
    #print(loop, T)
    ans = loop[(K - cnt)%T]
    print(ans)

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

journey = [1]

for i in range(2*n+1000):
    nxt = a[journey[-1]]
    journey.append(nxt)

if k < n+1:
    print((journey[k]))
    return

loop_end = n

loop_start = n-1

while(journey[loop_start] != journey[loop_end]):
    loop_start -= 1

period = loop_end - loop_start
k %= period

while k < n:
    k += period

print((journey[k]))