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

i = 0
his = []
n = 0
his.append(0)
while(1):
    #print(his)
    i = a[i] - 1
    if i not in his:
        his.append(i)
    else:
        n = len(his)-his.index(i)
        break
m = len(his) - n
p = 0
if k > m:
    p = (k-m)%n + m
else:
    p = k
i = 0
#print(n,m,p)
for j in range(p):
    #print(a[i])
    i = a[i] - 1
print((i+1))



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

i = 0
check = [True]*b
his = []
n = 0
his.append(0)
while(1):
    #print(his)
    i = a[i] - 1
    if check[i]:
        check[i] = False
        his.append(i)
    else:
        n = len(his)-his.index(i)
        break
m = len(his) - n
p = 0
if k > m:
    p = (k-m)%n + m
else:
    p = k
i = 0
#print(n,m,p)
for j in range(p):
    #print(a[i])
    i = a[i] - 1
print((i+1))
# Original solution
def D():
    n, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    next = a[0]
    path = [0]
    while not next in path:
        k -= 1
        if k==0:
            print(next)    
            break
        path.append(next)
        next = a[next - 1]
    if k!=0:
        cyclic = path[path.index(next):]
        print((cyclic[k%(len(cyclic))-1]))

D()

# Optimized solution
def D():
    n, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    next = a[0]
    path = [1]
    visited = [True] + [False]*(n-1)
    while not visited[next-1]:
        k -= 1
        if k==0:
            print(next)    
            break
        path.append(next)
        visited[next-1] = True 
        next = a[next-1]
    if k!=0:
        cyclic = path[path.index(next):]
        print((cyclic[k%(len(cyclic))-1]))

D()
# Original solution
def resolve():
  N, K = list(map(int, input().split(" ")))
  A = [int(x) - 1 for x in input().split(" ")]

  history = []
  current = 0
  if K < N:
    for i in range(K):
      current = A[current]
    print((current + 1))
    return True
  else:
    while True:
      history.append(current)
      current = A[current]
      if current in history:
        loop_length = len( history[history.index(current):] )
        if loop_length == 0:
          print((current + 1))
          return True

        length_to_loop = len( history[:history.index(current)] )
        additional_way = (K-length_to_loop)%loop_length
        print((history[length_to_loop + additional_way] + 1))
        return True

if __name__ == "__main__":
    resolve()

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

  current = 0
  if K < N:
    for i in range(K):
      current = A[current]
    print((current + 1))
    return True
  else:
    history = [False] * N
    load_map = []
    while True:
      load_map.append(current)
      current = A[current]
      if history[current]:
        loop_length = len( load_map[load_map.index(current):] )
        if loop_length == 0:
          print((current + 1))
          return True

        length_to_loop = len( load_map[:load_map.index(current)] )
        additional_way = (K-length_to_loop)%loop_length
        print((load_map[length_to_loop + additional_way] + 1))
        return True
      else:
        history[current] = True

if __name__ == "__main__":
    resolve()
# Original solution
# -*- coding: utf-8 -*-
N, K = list(map(int, input().split()))
A_list = list(map(int, input().split()))

ans_list = [1]
before_town = 1
loop_start_town = 10 ** 10
for i in range(N):
    now_town = A_list[before_town - 1]
    ans_list.append(now_town)
    before_town = now_town

if N >= K:
    print((ans_list[K]))
else:
    ans_list = sorted(set(ans_list), key = ans_list.index)
    loop_start_idx = ans_list.index(A_list[ans_list[-1] - 1])
    loop_len = len(ans_list)
    ans_list = ans_list[loop_start_idx:]
    mod_num = (K - loop_len) % (loop_len - loop_start_idx)
    print((ans_list[mod_num]))

# Optimized solution
# -*- coding: utf-8 -*-
N, K = list(map(int, input().split()))
A_list = list(map(int, input().split()))

ans_list = [1]
history_list = [0 for _ in range(N)]
before_town = 1
loop_start_town = 10 ** 10
for i in range(N):
    now_town = A_list[before_town - 1]
    if history_list[now_town - 1] == 1:
        break
    ans_list.append(now_town)
    before_town = now_town

if len(ans_list) > K:
    print((ans_list[K]))
else:
    loop_start_idx = ans_list.index(A_list[ans_list[-1] - 1])
    loop_len = len(ans_list)
    ans_list = ans_list[loop_start_idx:]
    mod_num = (K - loop_len) % (loop_len - loop_start_idx)
    print((ans_list[mod_num]))
# Original solution
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.insert(0,0)
start = 1
now = start
c = 0
flag = [0]*(n+1)
while c <= k and flag[now] == 0:
    #print(now)
    flag[now] = 1
    c+= 1
    now = a[now]
#print(c, now)
if c == k:
    print(now)
else:
    k-=c
    moto = now
    now = a[now]
    cc = 1
    while now != moto:
        now = a[now]
        cc+=1
    nokori = k % cc
    for i in range(nokori):
        now = a[now]
    print(now)


# Optimized solution
n,k = list(map(int, input().split()))
a = list(map(int, input().split()))
a.insert(0,0)
start = 1
now = start
c = 0
flag = [-1]*(n+1)
while c < k and flag[now] == -1:
    #print(now)
    flag[now] = c
    c+= 1
    now = a[now]
#print(c, now)
if c == k:
    print(now)
else:
    k-=c
    cc = c-flag[now]
    nokori = k % cc
    for i in range(nokori):
        now = a[now]
    print(now)
# Original solution
#167
#d
n,k = list(map(int, input().split()))
ln = list(map(int, input().split()))# まちi にいるとき次に町ln[i-1]へいく
visit = [0]*n 
now= 1
visit[0] =1
before =[1]
while max(visit) <= 1:
    now = ln[now -1]
    before.append(now)
    visit[now-1] += 1
roops = before.index(now)
roop_ln = before[roops:-1]
mae = before[:roops]
if k <len(mae):
    print((mae[k]))
elif len(mae) <= k :
    t = k- len(mae)
    print((roop_ln[t%len(roop_ln)]))

# Optimized solution
N,K = list(map(int,input().split()))
A = list(map(int,input().split()))
pos = 0
visit = [0] * N
move = []
roop = []
while visit[pos]!=2:
    if visit[pos]==0:
        move.append(pos)
    else:
        roop.append(pos)
    visit[pos] += 1
    pos = A[pos] - 1
if len(move)>K:
    print((move[K]+1))
else:
    print((roop[(K-(len(move)-len(roop)))%len(roop)]+1))
# Original solution
n, k = list(map(int, input().split()))

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

visited = [1]
now = 1
step = 0
for i in range(k):
    now = a[now-1]
    step += 1
    if now not in visited:
        visited.append(now)
    else:
        ind = visited.index(now)
        loop = visited[ind:]
        tmp = (k-step) % len(loop)
        now = loop[tmp]
        break

print(now)


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

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

visited = [1]
is_visited = [0] * n
now = 1
step = 0
for i in range(k):
    now = a[now-1]
    step += 1
    if is_visited[now-1] == 0:
        is_visited[now-1] = 1
        visited.append(now)
    else:
        ind = visited.index(now)
        loop = visited[ind:]
        tmp = (k-step) % len(loop)
        now = loop[tmp]
        break

print(now)
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
i2p = {0:1}
p2i = {1:0}
cur = A[0]
i = 1
while True:
    i2p[i] = cur
    p2i[cur] = i
    if A[cur-1] in list(i2p.values()):
        break
    cur = A[cur-1]
    i+=1
i = p2i[A[cur-1]]
num_loop = len(i2p) - i 
if K < i:
    print((i2p[K]))
else:
    print((i2p[i+(K-i)%num_loop]))

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

i2p = {0:1}
p2i = {1:0}
cur = A[0]
is_loop = {}
for i in range(N+1):
    is_loop[i] = False
i = 1
while True:
    i2p[i] = cur
    p2i[cur] = i
    is_loop[cur] = True
    if is_loop[A[cur-1]]:
        break
    cur = A[cur-1]
    i+=1
i = p2i[A[cur-1]]
num_loop = len(i2p) - i 
if K < i:
    print((i2p[K]))
else:
    print((i2p[i+(K-i)%num_loop]))
# Original solution
n,k = list(map(int, input().split()))
a = list(map(int,input().split()))
ans = 1
c = [1]
for j in range(1,2*n):
    i = a[c[-1]-1]
    if i in set(c):
        g = i
        break
    c.append(i)
s = c.index(g)
r = len(c)-s
if k <=s:
    print((c[k]))
else:
    b = (k-s)%r
    print((c[s+b]))

# Optimized solution
n,k = list(map(int, input().split()))
a = list(map(int,input().split()))
ans = 1
c = [1]
d = [0]*(n+5)
d[1] = 1
for j in range(1,2*n):
    i = a[c[-1]-1]
    if d[i] == 1:
        g = i
        break
    # if i in set(c):
    #     g = i
    #     break
    d[i] = 1
    c.append(i)
s = c.index(g)
r = len(c)-s
if k <=s:
    print((c[k]))
else:
    b = (k-s)%r
    print((c[s+b]))
# Original solution
n, k = list(map(int, input().split()))
a_li = list(map(int, input().split()))

loop_li = []
a = 1 

while a not in loop_li:
    loop_li.append(a)
    a = a_li[a-1]

length = len(loop_li)
if k<length:
    print((loop_li[k]))
else:
    bp = a_li[loop_li[-1]-1] # back point
    bp_idx = loop_li.index(bp)
    t = length - bp_idx
    amari = (k-bp_idx)%t
    print((loop_li[bp_idx+amari]))

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

loop_li = []
loop_set = set([])
a = 1 

while a not in loop_set:
    loop_li.append(a)
    loop_set.add(a)
    a = a_li[a-1]

length = len(loop_li)
if k<length:
    print((loop_li[k]))
else:
    bp = a_li[loop_li[-1]-1] # back point
    bp_idx = loop_li.index(bp)
    t = length - bp_idx
    amari = (k-bp_idx)%t
    print((loop_li[bp_idx+amari]))
# Original solution
n = input().split()
N = int(n[0])
K = int(n[1])

listb = [1]
C = 1
A = list(map(int, input().split()))
                 
for i in range(N):
    C = A[C-1]
    if C not in listb:
        listb.append(C)
    else:
        D = listb.index(C)
        listb.append(C)
        break

L = len(listb) -1

if K <= N:
    print((listb[K]))
else:
    if L-D == 1 or L-D == 0:
        print(C)
    else:
        M = (K-D) % (L-D)
        print((listb[(D+M)%L]))

# Optimized solution
n = input().split()
N = int(n[0])
K = int(n[1])

listb = [1]
listc = [0]*N
C = 1
A = list(map(int, input().split()))
                 
for i in range(N):
    C = A[C-1]
    if listc[C-1] == 0:
        listb.append(C)
        listc[C-1] = 1
    else:
        D = listb.index(C)
        listb.append(C)
        break

L = len(listb) -1

if K <= N:
    print((listb[K]))
else:
    if L-D == 1 or L-D == 0:
        print(C)
    else:
        M = (K-D) % (L-D)
        print((listb[(D+M)%L]))
# Original solution
N, K = list(map(int,input().split()))
A = list(map(int, input().split()))
dic = {1:0}
now = 1
flag = 0
T = 0
log = [1]
for i in range(K):
  now = A[now-1]
  if now in log:
    flag=1
    T=i+1-dic[now]
    break
  dic[now] = i+1
  log.append(now)
if flag!=1:
  print(now)
else:
  print((log[(K-dic[now])%T+dic[now]]))

# Optimized solution
N, K = list(map(int,input().split()))
A = list(map(int, input().split()))
dic = {1:0}
now = 1
flag = 0
T = 0
log = [1]
for i in range(K):
  now = A[now-1]
  #print(i+1,now)
  if now in dic:
    flag=1
    T=i+1-dic[now]
    log = log[dic[now]:]
    break
  dic[now] = i+1
  log.append(now)
if flag!=1:
  print(now)
else:
  print((log[(K-dic[now])%T]))
# Original solution
n, k = list(map(int, input().split()))
a = list(map(int, input().split()))

pos = -1
seen = [False] * n
hist = []
cycle = []
i = 0
while(seen[i] == False):
    seen[i] = True
    hist.insert(0, i)
    ne = a[i]-1
    i = ne
    if (seen[i] == True):
        pos = i

preCircle = len(hist)

cnt = 0
while(len(hist) != 0):
    b = hist[0]
    cycle.append(b)
    cnt += 1
    hist.pop(0)
    if (b == pos):
        break

preCircle -= cnt

cycle = list(reversed(cycle))

if (k < preCircle):
    print((hist[-k-1] + 1))
else:
    k -= preCircle
    ans = k % len(cycle)
    print((cycle[ans] + 1))



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

pos = -1
seen = [False] * n
last = [-1] * n
hist = []
i = 0
cnt = 0

while(seen[i] == False):
    seen[i] = True
    last[i] = cnt
    cnt += 1
    hist.append(i)
    ne = a[i]-1
    i = ne
    if (seen[i] == True):
        pos = i

cycle = hist[last[pos]:]
preCircle = last[pos]

if (k <= preCircle):
    print((hist[k] + 1))
else:
    k -= preCircle
    ans = k % len(cycle)
    print((cycle[ans] + 1))
# Original solution
# -*- coding: utf-8 -*-

# 入力を整数に変換して受け取る
def input_int():
    return int(eval(input()))


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return list(map(int, input().split()))


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n, k = input_to_int_map()
    a = {i + 1: int(val) for i, val in enumerate(input().split())}

    place = 1
    place_goneds = [place]
    i = 0
    loop_start_index = 0
    while i < n:
        place = a[place]
        goned = False
        for j, place_goned in enumerate(place_goneds):
            if place_goned == place:
                loop_start_index = j
                goned = True
                break

        if goned:
            break

        place_goneds.append(place)
        i += 1

    if k < len(place_goneds):
        return place_goneds[k]

    move_cnt = k - loop_start_index
    loop_list = place_goneds[loop_start_index:]
    return loop_list[move_cnt % len(loop_list)]


if __name__ == "__main__":
    print((main()))


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

# 入力を整数に変換して受け取る
def input_int():
    return int(eval(input()))


# マイナス1した値を返却
def int1(x):
    return int(x) - 1


# 半角スペース区切り入力をIntに変換してMapで受け取る
def input_to_int_map():
    return list(map(int, input().split()))


# 半角スペース区切り入力をIntに変換して受け取る
def input_to_int_tuple():
    return tuple(map(int, input().split()))


# 半角スペース区切り入力をIntに変換してマイナス1した値を受け取る
def input_to_int_tuple_minus1():
    return tuple(map(int1, input().split()))


def main():
    n, k = input_to_int_map()
    a = {i + 1: int(val) for i, val in enumerate(input().split())}

    place = 1
    visit = {place}
    place_visits = [place]
    for i in range(k):
        place = a[place]
        if place in visit:
            left = place_visits.index(place)
            return place_visits[left + (k - left) % (i + 1 - left)]
        else:
            visit.add(place)
            place_visits.append(place)

    return place


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

dic = {}
list_town = []
town = 1

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

for _ in range(K):
    list_town.append(town)
    town = dic[town]
    if town in list_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)

# Optimized solution
N, K = list(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)
# Original solution
def main():
  n,k,*a = list(map(int,open(0).read().split()))
  c = [0]
  visit = [False]*n
  visit[0] = True
  for i in range(n):
    nt = a[c[-1]]-1
    if visit[nt]:
      ws = c.index(nt)
      wst = c[:ws]
      wrt = c[ws:]
      wr = len(wrt)
    else:
      c.append(nt)
      visit[nt] = True
  if ws > k:
    ans = wst[k]
  else:
    ans = wrt[(k-ws)%wr]
  print((ans+1))
main()

# Optimized solution
def main():
  n,k,*a = list(map(int,open(0).read().split()))
  c = [0]
  visit = [False]*n
  visit[0] = True
  for i in range(n):
    nt = a[c[-1]]-1
    if visit[nt]:
      ws = c.index(nt)
      wst = c[:ws]
      wrt = c[ws:]
      wr = len(wrt)
      break
    else:
      c.append(nt)
      visit[nt] = True
  if ws > k:
    ans = wst[k]
  else:
    ans = wrt[(k-ws)%wr]
  print((ans+1))
main()
# Original solution

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

P=[1]
now=1

for i in range(K):
    now=A[now-1]
    if now in P:
        x = i+1
        y = P.index(now)
        break
    elif i == K-1:
        print(now)
        exit()
    else:
        P.append(now)

c=(K-y)%(x-y)

print((P[y+c]))

# Optimized solution

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

P=[1]
S=[0]*N
S[0]=1
now=1

for i in range(K):
    now=A[now-1]
    if S[now-1]==1:
        x = i+1
        y = P.index(now)
        break
    elif i == K-1:
        print(now)
        exit()
    else:
        P.append(now)
        S[now-1]=1

c=(K-y)%(x-y)

print((P[y+c]))
# Original solution
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    db = [a]
    cnt = k.bit_length()
    for c in range(1, cnt):
        temp = []
        for i in range(n):
            temp.append(db[c-1][db[c-1][i]-1])
        db.append(temp)

    res = 1
    for i in range(cnt):
        if (k>>i) & 1:
            res = db[i][res-1]
    print(res)

if __name__ == '__main__':
    main()

# Optimized solution
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    db = [a]
    cnt = k.bit_length()
    for c in range(1, cnt):
        temp = [0]*n
        for i in range(n):
            temp[i] = db[c-1][db[c-1][i]-1]
        db.append(temp)

    res = 1
    for i in range(cnt):
        if (k>>i) & 1:
            res = db[i][res-1]
    print(res)

if __name__ == '__main__':
    main()
# Original solution
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    db = [a]
    cnt = k.bit_length()
    for c in range(1, cnt):
        temp = [0]*n
        for i in range(n):
            temp[i] = db[c-1][db[c-1][i]-1]
        db.append(temp)

    res = 1
    for i in range(cnt):
        if (k>>i) & 1:
            res = db[i][res-1]
    print(res)

if __name__ == '__main__':
    main()

# Optimized solution
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    from itertools import combinations, permutations, accumulate, groupby, product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    import math
    #from math import gcd

    #inf = 10**17
    #mod = 10**9 + 7

    n,k = list(map(int, input().split()))
    a = [0] + list(map(int, input().split()))
    # visited[i]:町iにvisited[i]回目の遷移で到達
    visited = [0]*(n+1)
    step = 0
    i = 1

    while k:
        i = a[i]
        step += 1
        k -= 1
        if visited[i] != 0:
            k = k % (step - visited[i])
            for _ in range(k):
                i = a[i]
            print(i)
            break
        visited[i] = step
    else:
        print(i)

if __name__ == '__main__':
    main()
# Original solution
from sys import stdin
import math
n,k = list(map(int,stdin.readline().split()))
a = list(map(int,stdin.readline().split()))
d = math.floor(math.log2(k))
next = [[-1 for _ in range(n)] for _ in range(d+1)]
for i in range(n):
    next[0][i] = a[i] - 1
for j in range(d):
    for i in range(n):
        if next[j][i] == -1:
            continue
        next[j+1][i] = next[j][next[j][i]]
cur = 0
i = 0
while k > 0:
    if k&1:
        cur = next[i][cur]
    k >>= 1
    i += 1
print((cur+1))


# Optimized solution
from sys import stdin
n,k = list(map(int,stdin.readline().split()))
a = list(map(int,stdin.readline().split()))
for i in range(n):
    a[i] -= 1
d = {}
d[0] = 0
cur = 0
step = 0
while step < k:
    cur = a[cur]
    step += 1
    if cur in d:
        looplen = step - d[cur]
        step += looplen * ((k-step)//looplen)
    else:
        d[cur] = step
print((cur + 1))
# Original solution
from sys import stdin
n,k = list(map(int,stdin.readline().split()))
a = list(map(int,stdin.readline().split()))
for i in range(n):
    a[i] -= 1
d = {}
d[0] = 0
cur = 0
step = 0
while step < k:
    cur = a[cur]
    step += 1
    if cur in d:
        looplen = step - d[cur]
        step += looplen * ((k-step)//looplen)
    else:
        d[cur] = step
print((cur + 1))


# Optimized solution
from sys import stdin
n,k = list(map(int,stdin.readline().split()))
a = list(map(int,stdin.readline().split()))
for i in range(n):
    a[i] -= 1
d = {}
d[0] = k
cur = 0
while k > 0:
    cur = a[cur]
    k -= 1
    if cur in d:
        looplen = d[cur] - k
        k %= looplen
    else:
        d[cur] = k
print((cur + 1))
# Original solution
def resolve():
    n, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    roop=0
    iti=0
    rirekin=0
    rireki=[]
    while roop==0:
        iti=a[iti]-1
        if iti in rireki:
            mae=rireki.index(iti)
            Mae=rireki[:mae]
            del rireki[:mae]
            roop=rirekin-mae
            break
        rireki.append(iti)
        rirekin+=1
    if k <= mae:
        print((Mae[k-1]+1))
    else:
        k-=mae
        print((rireki[(k%roop)-1]+1))
resolve()

# Optimized solution
def resolve():
    n, k = list(map(int, input().split()))
    a = list(map(int, input().split()))
    check=[-1]*n
    iti=0
    rireki=[]
    while True:
        iti=a[iti]-1
        if check[iti]==0:
            mae=rireki.index(iti)
            Mae=rireki[:mae]
            Loop=rireki[mae:]
            roop=len(Loop)
            break
        rireki.append(iti)

        check[iti]=0
    if k <= mae:
        print((Mae[k-1]+1))
    else:
        k-=mae
        print((Loop[(k%roop)-1]+1))
resolve()
# Original solution
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))

X = 0
town = 1
counted = [0 for _ in range(N)]
for k in range(N):
  X += 1
  counted[k] = town
  town = A[town-1]
  if town in counted:
    ini = counted.index(town)
    Q = X - ini
    break
if K >= ini:    
  num = (K-ini) % Q
  print((counted[ini+num]))
else:
  print((counted[K]))


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

X = 0
town = 1
counted = [0 for _ in range(N)]
List = [0 for _ in range(N)]
for k in range(N):
  X += 1
  counted[k] = town
  town = A[town-1]
  if List[town-1] == 1:
    ini = counted.index(town)
    Q = X - ini
    break
  else:
    List[town-1] = 1
if K >= ini:    
  num = (K-ini) % Q
  print((counted[ini+num]))
else:
  print((counted[K]))