CodeEff/ECCO huggingface dataset:
# Original solution
def ma():
    return list(map(int,input().split()))
y="Yes"
t="No"
n,k=ma()
A=list(ma())
ans=[]
now=1
while True:
    ans.append(now)
    now=A[now-1]
    if now in ans:
        use=ans.index(now)
        tool=len(ans)-use
        break 

if use>=k:
    print((ans[k]))
    exit()
else:
    p=(k-use)%tool
    print((ans[use+p]))

# Optimized solution
def ma():
    return list(map(int,input().split()))
def main():
    n,k=ma()
    A=list(ma())
    ans=[]
    exp=[0]*(n+1)
    now=1
    
    while True:
        ans.append(now)
        exp[now]=1
        now=A[now-1]
        if exp[now]==1:
            use=ans.index(now)
            tool=len(ans)-use
            break 

    if use>=k:
        print((ans[k]))
        exit()
    else:
        p=(k-use)%tool
        print((ans[use+p]))

main()
# Original solution
N, K = list(map(int, input().split()))

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


from_ = 1
way = []
way.append(1)
for i in range(K):
    if(A[from_ - 1] in way):
        way.append(A[from_ - 1])
        break
    else:
        way.append(A[from_ - 1])
        from_ = A[from_ - 1]

key_from = way.index(way[len(way) - 1])
key_to = len(way) - 1



if(K > key_from):
    ans_loop = (K - key_from) % (key_to - key_from)
    ans_num = key_from + ans_loop
   
    print((way[ans_num]))
else:
    print((way[K]))

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

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


from_ = 1
way = []
way.append(1)
way_set = set([1])

for i in range(K):
    s = A[from_ - 1]
    if(s in way_set):
        way.append(s)
        break
    else:
        way.append(s)
        way_set.add(s)
        from_ = s

key_from = way.index(way[len(way) - 1])
key_to = len(way) - 1



if(K > key_from):
    ans_loop = (K - key_from) % (key_to - key_from)
    ans_num = key_from + ans_loop

    print((way[ans_num]))
else:
    print((way[K]))
# Original solution
N, K = list(map(int,input().split()))
ls_pass = [0]+list(map(int,input().split()))
a=1
b=0
c=0
d=0
ls_past=[1]
ls_cicle=[]
for i in range(1,N*3):
  b=a
  a=ls_pass[a]
  if b==a:
    print(a)
    break
  elif a in ls_past:
    if c==0:
      c=i
      d=a
      ls_cicle.append(d)
      continue
    elif a==d:
      print((ls_cicle[(K-c)%(i-c)]))
      break
    else:
      ls_cicle.append(a)
  elif i==K:
    print(a)
    break  
  else:
    ls_past.append(a)

# Optimized solution
N, K = list(map(int,input().split()))
ls_pass = [0]+list(map(int,input().split()))
a=1
b=0

ls=["ンゴ"]+[0]+["ンゴ"]*(N-1)
ls_past=[1]
for i in range(1,N*3):
  b=a
  a=ls_pass[a]
  if ls[a]!="ンゴ":
    ls_cicle=ls_past[ls[a]:i]
    print((ls_cicle[(K-i)%len(ls_cicle)]))
    break
  elif i==K:
    print(a)
    break  
  else:
    ls_past.append(a)
    ls[a]=i
# Original solution
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys

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

    nw = 1
    lp0 = [1]
    for i in range(N):
        nw = A[nw-1]
        if nw in lp0:
            break
        else:
            lp0.append(nw)
    lpc = i+1 - lp0.index(nw)
    lp = lp0[-lpc:]

    if K<=len(lp0)-1:
        print((lp0[K]))
    else:
        K-= len(lp0)-1
        K=K%lpc - 1
        print((lp[K]))

if __name__ == '__main__':
    main()


# Optimized solution
#!/usr/bin python3
# -*- coding: utf-8 -*-

import sys

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

    nw = 1
    lp0 = [1]
    lpl = {1}
    for i in range(N):
        nw = A[nw-1]
        if nw in lpl:
            break
        else:
            lp0.append(nw)
            lpl.add(nw)
    lpc = i+1 - lp0.index(nw)
    lp = lp0[-lpc:]

    if K<=len(lp0)-1:
        print((lp0[K]))
    else:
        K-= len(lp0)-1
        K=K%lpc - 1
        print((lp[K]))

if __name__ == '__main__':
    main()
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
 
h = []
i = 0
s = 1
 
ans = 0
while i < k: 
  g = a[s-1]
  if g not in h:
    h.append(g)
    s = g
    i+=1
  else:
    c = h.index(g)
    l = (k-1-c) % (i-c)
    ans = h[c+l]
    break
    
if ans == 0:
  ans = h[-1]
 
print(ans)

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

s = 1
g = 0
i = 1
history = [s]
flag = [False] * n
flag[0] = True

while True:
    g = a[s-1]
    if flag[g-1] == True:
        break
    else:
        flag[g-1] = True
        history.append(g)
        s = g
        i += 1


x = history.index(g)

if k < i:
    ans = history[k]
else:
    d = (k-x) % (i - x)

    ans = history[x + d]

print(ans)
# Original solution
def main():
    n, k, *a = list(map(int, open(0).read().split()))
    a = [0] + a
    root = [1]
    visited = [False for _ in range(n+1)]
    nx = 1
    visited[1] = True

    step = 0
    while True:
        step += 1
        now = nx
        nx = a[now]
        if step == k:
            print(nx)
            break
        if visited[nx]:
            end = step
            start = root.index(nx)
            d = end - start
            r = k - step
            index = start + r % d
            print((root[index]))
            break

        visited[nx] = True
        root.append(nx)

if __name__ == '__main__':
    main()


# Optimized solution
def main():
    n, k, *a = list(map(int, open(0).read().split()))
    a = [0] + a
    check = [0] * (n + 1)
    check[1] = 1

    i = 0
    nw = 1
    path = [1]
    while 1:
        nx = a[nw]
        i += 1
        if i == k:
            print(nx)
            break
        if check[nx]:
            j = path.index(nx)
            d = j + (k - i) % (i - j)
            print((path[d]))
            break
        path.append(nx)
        check[nx] = 1
        nw = nx


if __name__ == '__main__':
    main()
# Original solution
def main():
    n, k, *a = list(map(int, open(0).read().split()))
    a = [0] + a
    check = [0] * (n + 1)
    check[1] = 1

    i = 0
    nw = 1
    path = [1]
    while 1:
        nx = a[nw]
        i += 1
        if i == k:
            print(nx)
            break
        if check[nx]:
            j = path.index(nx)
            d = j + (k - i) % (i - j)
            print((path[d]))
            break
        path.append(nx)
        check[nx] = 1
        nw = nx


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    import sys
    n, k, *a = list(map(int, sys.stdin.read().split()))
    a = [0] + a
    check = [0] * (n + 1)
    check[1] = 1

    i = 0
    nw = 1
    path = [1]
    while 1:
        nx = a[nw]
        i += 1
        if i == k:
            print(nx)
            break
        if check[nx]:
            j = path.index(nx)
            d = j + (k - i) % (i - j)
            print((path[d]))
            break
        path.append(nx)
        check[nx] = 1
        nw = nx


if __name__ == '__main__':
    main()
# Original solution
def main():
    import sys
    n, k, *a = list(map(int, sys.stdin.read().split()))
    a = [0] + a
    check = [0] * (n + 1)
    check[1] = 1

    i = 0
    nw = 1
    path = [1]
    while 1:
        nx = a[nw]
        i += 1
        if i == k:
            print(nx)
            break
        if check[nx]:
            j = path.index(nx)
            d = j + (k - i) % (i - j)
            print((path[d]))
            break
        path.append(nx)
        check[nx] = 1
        nw = nx


if __name__ == '__main__':
    main()


# Optimized solution
def main():
    import sys
    n, k, *a = list(map(int, sys.stdin.read().split()))
    a = [0] + a
    check = [0] * (n + 1)
    check[1] = 1

    i = 0
    nw = 1
    path = [1]
    while True:
        nx = a[nw]
        i += 1
        if i == k:
            print(nx)
            break
        if check[nx]:
            j = path.index(nx)
            d = j + (k - i) % (i - j)
            print((path[d]))
            break
        path.append(nx)
        check[nx] = True
        nw = nx


if __name__ == '__main__':
    main()
# Original solution
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
route = [1]
dest = A[0]
while dest not in route:
    route.append(dest)
    dest = A[dest - 1]
ind = route.index(dest)
cycle = route[ind:]
if k >= ind:
    ans = (k - ind) % len(cycle)
    print((cycle[ans]))
else:
    print((route[k]))

# Optimized solution
n, k = list(map(int, input().split()))
A = list(map(int, input().split()))
route = [1]
dest = A[0]
check = {i: False for i in range(n)}
while not check[dest - 1]:
    check[dest - 1] = True
    route.append(dest)
    dest = A[dest - 1]
ind = route.index(dest)
cycle = route[ind:]
if k >= ind:
    ans = (k - ind) % len(cycle)
    print((cycle[ans]))
else:
    print((route[k]))
# Original solution
n,k=list(map(int,input().split()))
a=[0]+list(map(int,input().split()))

MAX_N=2*10**5
b=[1]
visited=[-1]*(n+10)
for i in range(1,2*MAX_N+1):
    nxt=a[b[-1]]
    b.append(nxt)
        
if k<=n:
    print((b[k]))
    exit()
# print(b)  
for i,bi in enumerate(b):
    if visited[bi]==-1:
        visited[bi]=i
    else:
        m=i-visited[bi]
        l=visited[bi]
        break
k=k%m

while k<n:
    k+=m
print((b[k]))
    

# Optimized solution
n,k,*a=list(map(int,open(0).read().split()))

now=1
if k<=n:
  for i in range(k):
    now=a[now-1]
  print(now)
  exit()
# 絶対ループする
visited=[False]*n
visited[now-1]=-1
for i in range(4*10**5):
  now=a[now-1]
  if visited[now-1]==False:
    visited[now-1]=i
  else:
    c,d=visited[now-1],i
    break

k=(k-c)%(d-c)+c
while k<n:
  k+=(d-c)
now=1
for i in range(k):
  now=a[now-1]
print(now)
# Original solution
#!/usr/bin/env python3
import itertools
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = [1]
if k > len(list(itertools.permutations(a))):
    for i in range(k % n):
        ans.append(a[ans[i] - 1])
    print((a[-1]))
else:
    for i in range(k):
        ans.append(a[ans[i] - 1])
    print((a[-2]))    


# Optimized solution
#!/usr/bin/env python3
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = [1]
loop_start = 0
loop = 0
for i in range(n):
    ans.append(a[ans[i] - 1])
for j in ans:
    if j in ans[:loop_start] or j in ans[loop_start+1:]:
        break
    loop_start += 1
loop = ans[loop_start+1:].index(j) + 1
ans.clear()
ans = [1]
if k < loop_start:
    for l in range(k):
        ans.append(a[ans[l] - 1])
    print((ans[k]))
else:
    for l in range(loop_start + loop):
        ans.append(a[ans[l] - 1])
    print((ans[((k-loop_start)%loop)+loop_start]))
# Original solution
#!/usr/bin/env python3
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = [1]
loop_start = 0
loop = 0
for i in range(n):
    ans.append(a[ans[i] - 1])
for j in ans:
    if j in ans[:loop_start] or j in ans[loop_start+1:]:
        break
    loop_start += 1
loop = ans[loop_start+1:].index(j) + 1
ans.clear()
ans = [1]
if k < loop_start:
    for l in range(k):
        ans.append(a[ans[l] - 1])
    print((ans[k]))
else:
    for l in range(loop_start + loop):
        ans.append(a[ans[l] - 1])
    print((ans[((k-loop_start)%loop)+loop_start]))


# Optimized solution
#!/usr/bin/env python3
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
ans = [1]
c = 1
for i in range(n):
    ans.append(a[ans[i] - 1])
b = ans.index(ans[n])
if k < b:
    for l in range(k):
        c = a[c - 1]
else:
    for l in range((k-b)%(n-b)+b):
        c = a[c - 1]
print(c)
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
memo = []
memo_cir = []
index = 0
flag = True
while flag:
    if index in memo:
        flag = False
    else:
        memo.append(index)
        index = a[index] - 1
flag = False
for i_ in memo:
    if i_ == index:
        flag = True
    if flag:
        memo_cir.append(i_)
if k + 1 >= (len(memo) - len(memo_cir)):
    k -= (len(memo) - len(memo_cir) - 1)
    print((memo_cir[(k % len(memo_cir)) - 1] + 1))
else:
    print((memo[k] + 1))


# Optimized solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))
memo = []
memo_cir = []
visited = [False] * n
index = 0
flag = True
while flag:
    if visited[index]:
        flag = False
    else:
        memo.append(index)
        visited[index] = True
        index = a[index] - 1
flag = False
for i_ in memo:
    if i_ == index:
        flag = True
    if flag:
        memo_cir.append(i_)
if k + 1 >= (len(memo) - len(memo_cir)):
    k -= (len(memo) - len(memo_cir) - 1)
    print((memo_cir[(k % len(memo_cir)) - 1] + 1))
else:
    print((memo[k] + 1))
# Original solution
N, K = list(map(int, input().split()))
a = [i - 1 for i in list(map(int, input().split()))]
logK = 1
while ((1 << logK) < K):
    logK += 1
doubling = [[-1 for _ in range(N)] for _ in range(logK)]
for i in range(N):
    doubling[0][i] = a[i]
for i in range(logK - 1):
    for j in range(N):
        doubling[i + 1][j] = doubling[i][doubling[i][j]]
now, i = 0, 0
while K > 0:
    if (K & 1):
        now = doubling[i][now]
    K = K >> 1
    i += 1
print((now + 1))


# Optimized solution
N, K = list(map(int, input().split()))
a = [i - 1 for i in list(map(int, input().split()))]
logK = K.bit_length()
doubling = [[-1 for _ in range(N)] for _ in range(logK)]
for i in range(N):
    doubling[0][i] = a[i]
for i in range(logK - 1):
    for j in range(N):
        doubling[i + 1][j] = doubling[i][doubling[i][j]]
now, i = 0, 0
while K > 0:
    if (K & 1):
        now = doubling[i][now]
    K = K >> 1
    i += 1
print((now + 1))
# Original solution
n, k = list(map(int, input().split()))

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

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

point = 1

dev = [1]
flag = 0

for i in range(1, k + 1):
    if cheak[point]:
        loop = i -cheak[point]
        pre_loop = cheak[point]
        flag = 1
        break
    else:
        cheak[point] = i
        point = a[point]
        dev.append(point)

if flag:
    rest = (k + 1- pre_loop) % loop
    for j in range(rest):
        point = a[point]
        dev.append(point)

print(point)

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

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

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

point = 1

dev = [1]
flag = 0

for i in range(1, k + 1):
    if cheak[point]:
        loop = i -cheak[point]
        pre_loop = cheak[point]
        flag = 1
        break
    else:
        cheak[point] = i
        point = a[point]
        #dev.append(point)

if flag:
    rest = (k + 1- pre_loop) % loop
    for j in range(rest):
        point = a[point]
        #dev.append(point)

print(point)
# Original solution
N, K = list(map(int, input().split()))
A_list = list(map(int, input().split()))

place = [0]

while True:
    next_place = A_list[place[-1]] - 1
    if next_place in place:
        idx = place.index(next_place)
        loop = place[idx:]
        break
    place.append(next_place)

if K < len(place):
    print((place[K] + 1))
else:
    print((loop[(K-idx)%len(loop)] + 1))

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

place = [0]
table = [0] * N
table[0] = 1

while True:
    next_place = A_list[place[-1]] - 1
    if table[next_place] == 1:
        idx = place.index(next_place)
        loop = place[idx:]
        break
    table[next_place] = 1
    place.append(next_place)

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

import sys

sys.setrecursionlimit(1000000000)
from collections import deque


seen = [0 for i in range(n)]

hist = deque([])  # 頂点の訪問履歴
pos = -1  # サイクルの1成分 -1はサイクル未発見


def dfs(x, p):  # pはxの親
    global pos  # global!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    seen[x] = 1
    hist.append(x)  # 訪れたらhistにappend
    if seen[A[x]-1] == 1:
        pos = A[x]-1
        return  # サイクルを発見したら、即すべてのdfsを終える
    # 残りはseen[x]=0のみ
    dfs(A[x]-1, x)
    if pos != -1: return  # 帰りがけ、サイクルが検出済みなら何もしない

    hist.pop()  # stackの末尾を消す
    # ループなく平和に終わったらpopできる
    return  # まあなくてもいいけどreturnは終了であることを強調


dfs(0, -1)

# この状態だと、サイクルに入る前に通った枝葉がhistに入ってる。
# 枝葉が終わったら、posからループの順番に頂点番号が入ってる。
cycle = []
while hist:
    qwe = hist.pop()
    cycle.append(qwe)
    if qwe == pos: break

roop = len(cycle)
sen = seen.count(1)

if k<=n:
    no = 0
    for i in range(k):
        no = A[no]-1
    print((no+1))
else:
    tmp = k-sen+roop
    tmp%=roop
    print((cycle[-tmp-1]+1))


# Optimized solution
n,k = list(map(int ,input().split()))
A = tuple(map(int, input().split()))
seen = [-1]*n
tmp = 0
count = 0

while True:
    tmp = A[tmp]-1
    count +=1
    if seen[tmp] != -1:
        seennum = seen.count(1)

        tm = tmp
        se = [-1]*n
        roopmem = []
        while True:

            if se[tm] != -1:
                roop = se.count(1)
                break
            else:
                roopmem.append(tm)
                se[tm] = 1
                tm = A[tm] - 1

        break
    else:
        seen[tmp] = 1

if k<=n:
    no = 0
    for i in range(k):
        no = A[no]-1
    print((no+1))
else:
    tmp = k-seennum
    tmp %= roop
    print((roopmem[tmp-1]+1))
# Original solution
N,K = list(map(int,input().split()))
A = list(map(int, input().split()))

l = [1]

now_town = 1
loop_town = 0
for i in range(N):
    now_town = A[now_town-1]
    if now_town in l:
        loop_town = l.index(now_town)
        break
    else:
        l.append(now_town)

loop_num = len(l)-loop_town
if K > loop_town:
    num = (K - loop_town)%loop_num + loop_town
else:
    num = K
# 
# num = (K+1)%len(l)
# print(l)

print((l[num]))

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

l = [1]
kanryou_town = [0]*(N+1)
kanryou_town[1] = 1
now_town = 1
loop_town = 0
for i in range(N):
    now_town = A[now_town-1]
    if kanryou_town[now_town] == 1:
        loop_town = l.index(now_town)
        break
    else:
        kanryou_town[now_town] = 1
        l.append(now_town)

loop_num = len(l)-loop_town
if K > loop_town:
    num = (K - loop_town)%loop_num + loop_town
else:
    num = K
#
# num = (K+1)%len(l)
# print(l)

print((l[num]))
# Original solution




data = input().split()

N, k = int(data[0]), int(data[1])

tab = []

data = input().split()
for i in range(N):
    tab.append(int(data[i]) - 1)


parcour = []

position = 0

while (not (position in parcour)):
    parcour.append(position)
    position = tab[position]
i = 0
while parcour[i] != position:
    i+= 1

sizeCycle = len(parcour) - i 

#print (parcour)
if (k < len(parcour)):
    print((parcour[k] + 1))
else:
    print((parcour[i + ((k - i) % sizeCycle)] + 1))
    


# Optimized solution




data = input().split()

N, k = int(data[0]), int(data[1])

tab = []

data = input().split()
for i in range(N):
    tab.append(int(data[i]) - 1)


parcour = []
tmp = [0] * N

position = 0

while (tmp[position] == 0):
    parcour.append(position)
    tmp[position] = 1
    position = tab[position]
i = 0
while parcour[i] != position:
    i+= 1

sizeCycle = len(parcour) - i 

#print (parcour)
if (k < len(parcour)):
    print((parcour[k] + 1))
else:
    print((parcour[i + ((k - i) % sizeCycle)] + 1))
# Original solution
n,k = list(map(int,input().split()))
L = list(map(int,input().split()))
X = [0]*(n+1)
X[0] = 1
for i in range(n):
  if L[X[i]-1] in X:
    X[i+1] = L[X[i]-1]  
    break
  X[i+1] = L[X[i]-1]
    
def f(lst,value):
  return [i for i,x in enumerate(lst) if x == value]
for x in X:
  if X.count(x) == 2:
    a = f(X,x)
    X_ans = X[a[0]:a[1]]
    break

if k <= a[0]:
  print((X[k]))
else:
  b = (k - a[0] + 1) % (a[1]-a[0])
  print((X_ans[b-1]))



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

loop = []
mark = ['t'] *n
i = 0
loop.append(1)
mark[0] = 0
while True:
  if mark[lst[i]-1] != 't':
    start = mark[lst[i]-1]
    last = mark[i]
    break
  else:
    mark[lst[i]-1] = mark[i] + 1
    loop.append(lst[i])
  i = lst[i]-1
  
  
loop_len = last - start +1
loop_num = loop[start:last+1]
first = start-1

if k <= first:
  print((loop[k]))
else:
  q = (k-first) % loop_len
  print((loop_num[q-1]))
# Original solution
def roop(now, a_list):
    return a_list[now-1]

if __name__ == '__main__':
    n, k = list(map(int, input().split()))
    a_list = list(map(int, input().split()))
    
    now = 1
    check = [1]
    for i in range(k):
        now = roop(now, a_list)
        if now not in check:
            check.append(now)
        else: 
            break

    point = (check.index(now))
    roop_len = len(check) - point

    if k <= len(check):
        print((check[k]))
    else:
        k_ = k - point
        point_ = k_ % roop_len
        print((check[point+point_]))

# Optimized solution
if __name__ == '__main__':
    n, k = list(map(int, input().split()))
    a_list = list(map(int, input().split()))
    
    now = 1
    check = [0] * n
    check[0] = 1
    move = [1]
    for i in range(k):
        now = a_list[now-1]
        move.append(now)
        if check[now-1] == 0:
            check[now-1] = 1
        else: 
            break

    point = (move.index(now))
    roop_len = sum(check) - point

    if k <= sum(check):
        print((move[k]))
    else:
        k_ = k - point
        point_ = k_ % roop_len
        print((move[point+point_]))
# Original solution
import sys

input = lambda: sys.stdin.readline()


def cin_int_list():
    return [int(x) for x in input().split()]


def cin_int_iter():
    return (int(x) for x in input().split())


def cin_int():
    return int(eval(input()))


def cout_int_iter(a):
    print((' '.join(map(str, a))))


def iota(n, start=0):
    return list(range(start, n))


def cin_digits_list():
    return [ord(x) - ord('0') for x in eval(input())]


def main():
    n, k = cin_int_iter()

    g = {}

    cycle_starts = None
    for u, x in enumerate(cin_int_list()):
        v = x - 1
        g[u] = v
        if v in g:
            cycle_starts = v

    if cycle_starts is not None:
        cycle_len = 0

        u = cycle_starts
        cycle = []
        while True:
            cycle.append(u)
            u = g[u]

            if u == cycle_starts:
                break

        before_cycle = []
        u = 0

        while u != cycle_starts:
            before_cycle.append(u)
            u = g[u]

        if k < len(before_cycle):
            print((before_cycle[k] + 1))
            return

        if before_cycle:
            k -= len(before_cycle)

        print((cycle[k % len(cycle)] + 1))
        return

    u = 0
    while k:
        u = g[u]
        k -= 1

    print((u + 1))




main()


"""
6 1
6 5 2 5 3 2

6 2
6 5 2 5 3 2

6 3
6 5 2 5 3 2

6 4
6 5 2 5 3 2

6 6
6 5 2 5 3 2

6 5
6 5 2 5 3 2


no cycle

4 1
2 3 4 5

4 111111111111111111
2 3 4 1
"""

# Optimized solution
import sys

input = lambda: sys.stdin.readline()


def cin_int_list():
    return [int(x) for x in input().split()]


def cin_int_iter():
    return (int(x) for x in input().split())


def cin_int():
    return int(eval(input()))


def cout_int_iter(a):
    print((' '.join(map(str, a))))


def iota(n, start=0):
    return list(range(start, n))


def cin_digits_list():
    return [ord(x) - ord('0') for x in eval(input())]


def main():
    n, k = cin_int_iter()

    g = {}

    for u, x in enumerate(cin_int_list()):
        v = x - 1
        g[u] = v

    visited = set()

    u = 0
    while u not in visited:
        visited.add(u)
        u = g[u]

    cycle_starts = u

    u = cycle_starts
    cycle = []
    while True:
        cycle.append(u)
        u = g[u]

        if u == cycle_starts:
            break

    before_cycle = []
    u = 0

    while u != cycle_starts:
        before_cycle.append(u)
        u = g[u]

    if k < len(before_cycle):
        print((before_cycle[k] + 1))
        return

    if before_cycle:
        k -= len(before_cycle)

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




main()


"""
6 1
6 5 2 5 3 2

6 2
6 5 2 5 3 2

6 3
6 5 2 5 3 2

6 4
6 5 2 5 3 2

6 6
6 5 2 5 3 2

6 5
6 5 2 5 3 2


no cycle

4 1
2 3 4 5

4 111111111111111111
2 3 4 1

1 111111111111111111
1

2 1999999999999999999
2 1

3 99999999999999999999
2 3 2

3 99999999999999999999
2 3 4
"""