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: MEDIUM

Solutions:
(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) = map(int, input().split())
A = [int(i) - 1 for i in input().split()]
X = [-1] * N
i = 0
t = 0
while X[i] < 0:
	X[i] = t
	i = A[i]
	t += 1
X[i] + (K - X[i]) % (t - X[i])
if K <= X[i]:
	print(X.index(K) + 1)
else:
	print(X.index(X[i] + (K - X[i]) % (t - X[i])) + 1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = []
ord = [-1 for i in range(n + 1)]
v = 1
c = 1
l = 0
while ord[v] == -1:
	ord[v] = len(s)
	s.append(v)
	v = a[v - 1]
c = len(s) - ord[v]
l = ord[v]
if k < l:
	print(s[k])
else:
	k -= l
	k %= c
	print(s[l + k])


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


(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) = map(int, input().split())
b = list(map(int, input().split()))
a = 0
for i in range(n):
	b[i] -= 1
if k < n:
	for _ in range(k):
		a = b[a]
	print(a + 1)
	exit()
c = [-1] * n
cc = 0
se = set()
while a not in se:
	c[a] = cc
	cc += 1
	se.add(a)
	a = b[a]
for _ in range((k - c[a]) % (cc - c[a])):
	a = b[a]
print(a + 1)


(n, k, *a) = map(int, open(0).read().split())
a = [x - 1 for x in a]
dist = [0] * n
cur = 0
while True:
	nxt = a[cur]
	if k == 0:
		print(cur + 1)
		break
	if dist[nxt]:
		k = (k - dist[nxt]) % (dist[cur] - dist[nxt] + 1) + dist[nxt]
		k -= 1
		dist = [0] * n
		cur = nxt
	else:
		k -= 1
		dist[nxt] = dist[cur] + 1
		cur = nxt


(n, k) = map(int, input().split())
num = list(map(int, input().split()))
t = [-1] * n
count = 0
s = 1
while t[s - 1] == -1:
	if count == k:
		break
	t[s - 1] = count
	count += 1
	s = num[s - 1]
else:
	z = (k - t[s - 1]) % (count - t[s - 1])
	s = t.index(t[s - 1] + z) + 1
print(s)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
V = [-1] * N
X = 0
V[0] = 0
T = 0
while T < K:
	T += 1
	X = A[X] - 1
	if V[X] != -1:
		t = T - V[X]
		k = (K - T) % t
		for i in range(k):
			X = A[X] - 1
		break
	V[X] = T
print(X + 1)


(n, k) = map(int, input().split())
a = [int(i) for i in input().split()]
d = {0: 1}
b = {1: 0}
p = 0
for i in range(k):
	d[i + 1] = a[p]
	b[a[p]] = i + 1
	p = a[p] - 1
	if a[p] in b:
		k = (k - b[a[p]]) % (i + 2 - b[a[p]]) + b[a[p]]
		break
print(d[k])


import numpy as np

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]
	begin = order_num[node]
	if k <= begin:
		print(path_history[k])
	else:
		leng = len(path_history) - order_num[node] + 1
		index = (k - (begin - 1)) % leng
		print(path_history[begin - 1 + index])
main()


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


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
t = {1: 0}
g = {0: 1}
(c, d) = (1, 0)
while d != k:
	d += 1
	c = a[c - 1]
	if c in t:
		print(g[t[c] + (k - t[c]) % (d - t[c])])
		exit()
	else:
		t[c] = d
		g[d] = c
print(c)


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


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
adj = [1] * n
b = [1]
now = 0
while adj[now]:
	adj[now] = 0
	now = a[now] - 1
	b.append(now + 1)
loop_start = b.index(b[-1])
loop = b[loop_start:-1]
p = len(loop)
if k < loop_start:
	print(b[k])
else:
	k -= loop_start
	k %= p
	print(loop[k])


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
n = [1]
t = 1
ord = [-1] * (N + 1)
ord[0] = 0
while True:
	t = A[t - 1]
	if ord[t] != -1:
		f = n.index(t)
		break
	n.append(t)
	ord[t] = 0
k = len(n) - f
if K >= f:
	print(n[f + (K - f) % k])
else:
	print(n[K])


(N, K, *A) = map(int, open(0).read().split())
x = 1
C = [None] * N
C[0] = 0
c = 0
while c < K:
	x = A[x - 1]
	c += 1
	if C[x - 1] is None:
		C[x - 1] = c
	else:
		a = C[x - 1]
		b = c - a
		K = (K - a) % b + a + b
		while c < K:
			x = A[x - 1]
			c += 1
		break
print(x)


(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(int, input().split()))
vis = [0] * N
p = 1
Town = []
while vis[p - 1] == 0:
	Town.append(p)
	vis[p - 1] = 1
	p = A[p - 1]
l = Town.index(p)
if K < len(Town):
	print(Town[K])
else:
	print(Town[l + (K - l) % len(Town[l:])])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = []
ord = [-1] * (n + 1)
v = 1
while ord[v] == -1:
	ord[v] = len(s)
	s.append(v)
	v = a[v - 1]
c = len(s) - ord[v]
l = ord[v]
ans = 0
if k < l:
	ans = s[k]
else:
	k -= l
	k %= c
	ans = s[l + k]
print(ans)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a = [i - 1 for i in a]
g = [-1] * n
i = 0
j = 0
while g[j] == -1:
	if i == k:
		print(j + 1)
		exit()
	g[j] = i
	i += 1
	j = a[j]
for i in range((k - g[j]) % (i - g[j])):
	j = a[j]
print(j + 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()))
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) = 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[v] = len(root)
	root.append(v)
	v = A[v] - 1
l = ord[v]
c = len(root) - l
if K < l:
	ans = root[K]
else:
	K -= l
	K %= c
	ans = root[l + K]
print(ans + 1)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
s = []
d = [-1] * (N + 1)
v = 1
(c, l) = (1, 0)
while d[v] == -1:
	d[v] = len(s)
	s.append(v)
	v = A[v - 1]
c = len(s) - d[v]
l = d[v]
if K < l:
	print(s[K])
else:
	K -= l
	K %= c
	print(s[l + K])


(N, K) = map(int, input().split())
a = list(map(int, input().split()))
s = []
ord = [-1] * (N + 1)
c = 1
l = 0
v = 1
while ord[v] == -1:
	ord[v] = len(s)
	s.append(v)
	v = a[v - 1]
c = len(s) - ord[v]
l = ord[v]
if K < l:
	print(s[K])
else:
	K -= l
	K %= c
	print(s[l + K])


(n, k) = map(int, input().split())
ls = list(map(lambda x: int(x) - 1, input().split()))
ved = [-1] * n
ved[0] = 0
cur = 0
i = k
while i > 0:
	cur = ls[cur]
	i -= 1
	if ved[cur] >= 0:
		i = i % (k - i - ved[cur])
	else:
		ved[cur] = k - i
print(cur + 1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
a = [i - 1 for i in a]
v = [-1 for _ in range(n)]
p = 0
x = 0
c = 0
while k > 0 and v[x] < 0:
	v[x] = p + 1
	p = v[x]
	x = a[x]
	c += 1
	k -= 1
z = c - v[x] + 1
k = k % z
while k > 0:
	k -= 1
	x = a[x]
print(x + 1)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
L = [1]
S = {1}
while A[L[-1] - 1] not in S:
	last = L[-1] - 1
	L.append(A[last])
	S |= {A[last]}
a = A[L[-1] - 1]
j = L.index(a)
r = len(L)
l = r - j
if k + 1 <= j:
	print(L[k])
else:
	print(L[j + (k - j) % l])


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:]

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
	elif a > b:
		return 1
	elif a < b:
		return -1
	else:
		return 0

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

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)

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

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


(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(lambda c: int(c) - 1, input().split()))
V = [-1] * N
i = 0
l = 0
while True:
	if V[i] != -1:
		break
	V[i] = l
	i = A[i]
	l += 1
	if l == K:
		print(i + 1)
		raise SystemExit
cyc = l - V[i]
K -= V[i]
K %= cyc
for _ in range(K):
	i = A[i]
print(i + 1)


(N, K) = map(int, input().split())
A = [int(x) - 1 for x in input().split()]
dist = {0: 0}
t = i = 0
while K > 0:
	K -= 1
	i += 1
	t = A[t]
	if t in dist:
		K %= i - dist[t]
	else:
		dist[t] = i
print(t + 1)


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)


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


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)


import sys
(a, b) = map(int, input().split())
b = b + 1
l = [0] * a
List = list(map(int, input().split()))
i = 0
j = 1
while l[i] == 0 and j < b:
	l[i] += j
	j += 1
	i = List[i] - 1
if j == b:
	print(i + 1)
	sys.exit()
roop = j - l[i]
c = (b - j) % roop
for y in range(len(l)):
	if l[y] == c + l[i]:
		print(y + 1)
		sys.exit()


(N, K) = map(int, input().split())
A = [int(v) - 1 for v in input().split()]
p = 0
memo = {}
for i in range(K):
	if p in memo:
		interval = i - memo[p]
		rest = (K - i - 1) % interval
		for j in range(rest + 1):
			p = A[p]
		print(p + 1)
		exit()
	else:
		memo[p] = i
	p = A[p]
print(p + 1)


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


(n, k, *a) = map(int, open(0).read().split())
v = [0] + [-1] * n
p = 0
for i in range(n):
	t = a[p] - 1
	if v[t] >= 0:
		(l, r) = (v[t], i + 1)
		break
	v[t] = i + 1
	p = t
print(v.index(min(k, l + (k - l) % (r - l))) + 1)


(N, K) = map(int, input().split())
a = list(map(int, input().split()))
l = [1]
for i in range(N):
	l.append(a[l[i] - 1])
p = l.index(l[N])
if K <= N:
	print(l[K])
else:
	x = (K - N + 1) % (N - p)
	if x == 0:
		print(l[N - 1])
	else:
		print(l[x + p - 1])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
l = [1]
for i in range(n):
	l.append(a[l[i] - 1])
p = l.index(l[-1])
if k <= n:
	print(l[k])
	exit()
x = (k - n + 1) % (n - p)
if x == 0:
	print(l[n - 1])
else:
	print(l[x + p - 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])


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:
		cur = a[cur]
		if not loopout and visit[cur]:
			if loopstart == cur:
				k = (k - sum(visit)) % loop
				loopout = True
				i = 0
				continue
			elif loopstart == -1:
				loopstart = cur
			loop += 1
		else:
			visit[cur] = True
		i += 1
	print(cur + 1)

def __starting_point():
	main()
__starting_point()


(n, k) = [int(x) for x in input().split()]
p = [int(x) - 1 for x in input().split()]
alp = [0 for _ in range(n)]
a = [0]
i = 0
alp[0] = 1
while alp[p[i]] == 0:
	a.append(p[i])
	alp[p[i]] = 1
	i = p[i]
l = a.index(p[i])
if k <= l:
	print(1 + a[k])
else:
	print(1 + a[l + (k - l) % (len(a) - l)])


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


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
e = [False] * (N + 1)
idx = 1
move = []
while True:
	if e[idx]:
		break
	move.append(idx)
	e[idx] = True
	idx = A[idx - 1]
m = move.index(idx)
c = len(move) - m
if K <= m:
	print(move[K])
else:
	print(move[m + (K - m) % c])


import numpy as np

def main():
	(n, k) = list(map(int, input().split()))
	warps = list(map(int, input().split()))
	warps = [0] + warps
	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]
	begin = order_num[node]
	if k <= begin:
		print(path_history[k])
	else:
		leng = len(path_history) - order_num[node] + 1
		index = (k - (begin - 1)) % leng
		print(path_history[begin - 1 + index])
main()


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 __starting_point():
	main()
__starting_point()


(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:
	visited[cur - 1] = cnt
	loop.append(cur)
	cnt += 1
	cur = A[cur - 1]
	if cnt == K:
		print(cur)
		break
else:
	loop = loop[visited[cur - 1]:]
	T = cnt - visited[cur - 1]
	ans = loop[(K - cnt) % T]
	print(ans)


(n, k) = map(int, input().split())
now = 0
a = list(map(int, input().split()))
s = []
od = [-1] * (n + 1)
c = 1
l = 0
v = 1
while od[v] == -1:
	od[v] = len(s)
	s.append(v)
	v = a[v - 1]
c = len(s) - od[v]
l = od[v]
if k < l:
	print(s[k])
else:
	k -= l
	k %= c
	print(s[l + k])


(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]
elif (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())
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)


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
		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 = int(next(tokens))
	K = int(next(tokens))
	A = [int(next(tokens)) for _ in range(N)]
	answer = solve(N, K, A)
	print(answer)

def __starting_point():
	main()
__starting_point()


(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 = list(map(int, input().split()))
b = 0
if k <= n:
	for i in range(k):
		b = a[b] - 1
	print(b + 1)
	exit(0)
c = [0]
for i in range(n):
	b = a[b] - 1
	c.append(b)
d = c[:-1].index(c[-1])
c = c[d:-1]
k = k - d
print(c[k % len(c)] + 1)


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


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
s = []
order = [-1] * (n + 1)
l = 1
while order[l] == -1:
	order[l] = len(s)
	s.append(l)
	l = A[l - 1]
new = s[order[l]:]
t = len(new)
first = len(s) - t
if k > first:
	print(new[(k - first) % t])
else:
	print(s[k])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
v = [0] * n
v[0] = 1
i = 1
l = [1]
while True:
	i = a[i - 1]
	l.append(i)
	if v[i - 1]:
		t = i
		break
	else:
		v[i - 1] = 1
pre = l.index(t)
loop = len(l) - pre - 1
if pre >= k:
	print(l[k])
else:
	k = k - pre
	mod = k % loop
	print(l[pre + mod])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
result = [1]
temp = 1
for i in range(n):
	temp = a[temp - 1]
	result.append(temp)
temp = result.index(result[len(result) - 1])
c = len(result) - temp - 1
if k < n:
	print(result[k])
else:
	print(result[temp + (k - temp) % c])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = [-1] * n
c = []
ans = 0
for i in range(k):
	s[ans] = i
	c.append(ans)
	ans = a[ans] - 1
	if s[ans] >= 0:
		t = i - s[ans] + 1
		ans = c[(k - i - 1) % t + s[ans]]
		break
print(ans + 1)


(N, K) = map(int, input().split())
(*A,) = map(int, input().split())
s = 0
l = 0
n = 0
h = [0] * N
while True:
	h[s] = l
	s = A[s] - 1
	l += 1
	if h[s]:
		n = l - h[s]
		break
if K < h[s]:
	s = 0
else:
	K -= h[s]
	K = K % n
while K > 0:
	s = A[s] - 1
	K = K - 1
print(s + 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) = [int(i) for i in input().split()]
l = [int(i) - 1 for i in input().split()]
i = 0
m = [-1] * n
p = 0
while m[i] == -1:
	if p == k:
		break
	m[i] = p
	p += 1
	i = l[i]
else:
	z = (k - m[i]) % (p - m[i])
	i = m.index(m[i] + z)
print(i + 1)


f = lambda : map(int, input().split())
(n, k) = f()
a = list(f())
lv = [-1] * n
lv[0] = 0
p = 0
for i in range(n):
	t = a[p] - 1
	if lv[t] >= 0:
		(l, r) = (lv[t], i + 1)
		break
	lv[t] = i + 1
	p = t
print(lv.index(l + (k - l) % (r - l) if k > l else k) + 1)


(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) = map(int, input().split())
a = list(map(int, input().split()))
s = []
o = [-1] * (n + 1)
i = 1
c = 1
l = 0
while o[i] == -1:
	o[i] = len(s)
	s.append(i)
	i = a[i - 1]
c = len(s) - o[i]
l = o[i]
if k < l:
	print(s[k])
else:
	k -= l
	k %= c
	print(s[l + k])


(N, K) = list(map(int, input().split()))
l = list(map(int, input().split()))
roop = [1]
s = set([1])
now = l[0]
while now not in s:
	roop.append(now)
	s.add(now)
	now = l[now - 1]
start = roop.index(now)
if len(roop) <= K:
	K -= start
	K = K % (len(roop) - start)
	print(roop[start + K])
else:
	print(roop[K])


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
t_zero = [-1] * N
t = 0
a = 1
while t_zero[a - 1] == -1:
	if t == K:
		break
	t_zero[a - 1] = t
	t += 1
	a = A[a - 1]
else:
	k = (K - t_zero[a - 1]) % (t - t_zero[a - 1])
	a = t_zero.index(t_zero[a - 1] + k) + 1
print(a)


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


def input2():
	return map(int, input().split())

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


(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()))
c = 1
path = []
d = {}
l = 0
while l <= k:
	if c in d:
		p = d[c]
		pattern_l = l - p
		k -= (k - p) // pattern_l * pattern_l
	path.append(c)
	l += 1
	d[c] = l - 1
	c = A[c - 1]
print(path[k])


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
s = 1
c = 0
d = {}
t = []
while not s in d.keys():
	d[s] = c
	t.append(s)
	c += 1
	s = a[s - 1]
l = c - d[s]
m = len(d.keys()) - l
if m >= k:
	print(t[k])
else:
	print(t[(k - m) % l + m])


(N, K) = map(int, input().split())
s = input().split(' ')
p = 1
l = -1
dict = {}
for i in range(K):
	if s[p - 1] in dict:
		x = dict[s[p - 1]]
		l = i
		break
	else:
		dict[s[p - 1]] = i
	p = int(s[p - 1])
if l != -1:
	for i in range((K - l) % (l - x)):
		p = int(s[p - 1])
print(p)


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


(N, K, *A) = map(int, open(0).read().split())
f = [0] * N
l = 1
ff = 0
f[l - 1] = K
while K > 0:
	l = A[l - 1]
	K -= 1
	if f[l - 1] != 0:
		K = K % (f[l - 1] - K)
		break
	f[l - 1] = K
while K > 0:
	l = A[l - 1]
	K -= 1
print(l)


(N, K) = map(int, input().split())
A = [int(x) - 1 for x in input().split()]
B = [0]
visited = [False] * N
for (g, here) in enumerate(B):
	if visited[here]:
		break
	visited[here] = True
	B.append(A[here])
s = B.index(here)
r = (K - s) % (g - s)
ans = B[s:][r] + 1 if K >= s else B[K] + 1
print(ans)


(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(int, ('0 ' + input()).split()))
c = [0] * (N + 1)
i = 1
cnt = 0
f = True
while cnt < K:
	if f and (c[A[i]] or A[i] == 1):
		loop = cnt - c[A[i]] + 1
		cnt += (K - cnt - 1) // loop * loop
		f = False
	cnt += 1
	i = A[i]
	c[i] = cnt
print(i)


(n, k) = list(map(int, input().split()))
a = list(map(int, input().split()))
b = [-1] * (n + 1)
tmp = []
here = 1
count = 0
while True:
	if b[here] != -1:
		roop = count - b[here]
		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]


(n, k) = map(int, input().split())
arr = list(map(int, input().split()))
l = [-1] * (n + 1)
tmp = []
pos = 1
cnt = 0
while 1:
	if l[pos] != -1:
		t = cnt - l[pos]
		if k < cnt:
			print(tmp[k])
		else:
			print(tmp[l[pos] + (k - cnt) % t])
		break
	l[pos] = cnt
	cnt += 1
	tmp.append(pos)
	pos = arr[pos - 1]


([n, k], [*a]) = [[*map(int, t.split())] for t in open(0)]
count = 0
visited = dict()
tmp = 1
while count < k:
	visited[tmp] = count
	count += 1
	tmp = a[tmp - 1]
	if tmp in visited:
		k = (k - count) % (count - visited[tmp])
		visited = {tmp: 0}
		count = 0
print(tmp)


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


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


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
route = [1]
for i in range(N):
	route.append(A[route[i] - 1])
prepart = route.index(route[-1])
cycle = len(route) - prepart - 1
if K > N:
	K = (K - prepart) % cycle + prepart
print(route[K])


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
t_zero = [-1] * N
t = 0
a = 1
while t_zero[a - 1] == -1:
	if t == K:
		break
	t_zero[a - 1] = t
	t += 1
	a = A[a - 1]
else:
	k = (K - t_zero[a - 1]) % (t - t_zero[a - 1])
	for _ in range(k):
		a = A[a - 1]
print(a)


(n, k) = map(int, input().split())
alist = list(map(int, input().split()))
memo = []
p = 1
vis = ['.'] * n
while vis[p - 1] == '.':
	memo.append(p)
	vis[p - 1] = 'v'
	p = alist[p - 1]
loop = memo.index(p)
if k < len(memo):
	print(memo[k])
else:
	print(memo[loop + (k - loop) % (len(memo) - loop)])


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


(N, K) = map(int, input().split())
A = tuple(map(int, input().split()))
L = [0 for i in range(N + 1)]
L[1] = 1
x = 1
t = 1
while K > 0:
	t += 1
	K -= 1
	x = A[x - 1]
	if L[x] != 0:
		p = t - L[x]
		K %= p
		break
	else:
		L[x] = t
while K > 0:
	x = A[x - 1]
	K -= 1
print(x)


(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()))
visited = [0 for i in range(N + 1)]
p = 1
path = [p]
visited[p] = 1
p = A[p - 1]
while visited[p] == 0:
	path.append(p)
	visited[p] = 1
	p = A[p - 1]
i = path.index(p)
if K < i:
	print(path[K])
else:
	K -= i
	print(path[i + K % (len(path) - i)])


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


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
	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()))
a = list(map(int, input().split()))
c = [0 for i in range(n)]
l = 1
u = 0
f = True
while True:
	u += 1
	l = a[l - 1]
	if u == k:
		print(l)
		f = False
	if c[l - 1]:
		break
	else:
		c[l - 1] = u
k = (k - c[l - 1]) % (u - c[l - 1])
while k:
	k -= 1
	l = a[l - 1]
if f:
	print(l)


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
x = 0
t = 0
d = [0] * N
v = [-1] * N
while t == 0 or x != 0:
	v[x] = t
	t += 1
	if v[A[x] - 1] >= 0:
		break
	x = A[x] - 1
	d[t] = x
c = t - v[A[x] - 1]
print(d[K] + 1 if K < t else d[(K - t) % c + v[A[x] - 1]] + 1)


(n, k) = map(int, input().split())
a = list(map(int, input().split()))
visited = []
o = (n + 1) * [-1]
(cycle, l) = (1, 0)
v = 1
while o[v] == -1:
	o[v] = len(visited)
	visited.append(v)
	v = a[v - 1]
cycle = len(visited) - o[v]
l = o[v]
if k < l:
	print(visited[k])
else:
	k -= l
	k %= cycle
	print(visited[l + k])


((N, K), A) = [[*map(int, line.split())] for line in open(0)]
kiseki = [0] * N
now = 0
for i in range(N):
	kiseki[i] = now
	now = A[now] - 1
p = kiseki.index(now)
ans = p + (K - p) % (N - p) if p < K else K
print(kiseki[ans] + 1)


(n, k) = map(int, input().split())
A = list(map(int, input().split()))
a = [0] * n
a[0] = 1
nxt = A[0] - 1
i = 2
while 1:
	a[nxt] = i
	nxt = A[nxt] - 1
	i += 1
	if a[nxt] != 0:
		g = i - a[nxt]
		t = a[nxt] - 1
		break
if t >= k:
	print(a.index(k + 1) + 1)
else:
	k -= t
	u = k % g
	print(a.index(t + u + 1) + 1)


(n, k) = map(int, input().split())
lt = [0] + [int(x) for x in input().split()]
h = {1}
g = [1]
for _ in range(n):
	x = lt[g[-1]]
	g.append(x)
	if x in h:
		break
	h.add(x)
if k > len(g):
	i = g.index(g[-1])
	b = len(g) - i - 1
	k = (k - i) % b + i
print(g[k])


(N, K) = map(int, input().split())
A = list(map(int, input().split()))
l = [1]
seen = {}
k = 1
for i in range(K):
	if not k in seen.keys():
		seen[k] = i
		k = A[k - 1]
		l.append(k)
	else:
		r_start = seen[k]
		roop = i - r_start
		K = (K - r_start) % roop + r_start
		break
ans = l[K]
print(ans)


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)


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) = map(int, input().split())
A = list(map(int, input().split()))
B = [True] * N
C = [1]
now = 0
while B[now]:
	B[now] = False
	now = A[now] - 1
	C.append(now + 1)
start = C.index(C[-1])
D = C[start:-1]
L = len(D)
if K < start:
	print(C[K])
else:
	K -= start
	K %= L
	print(D[K])


(n, k) = map(int, input().split())
l = list(map(int, input().split()))
kiseki = [-1] * n
i = 0
v = 1
while kiseki[v - 1] == -1:
	kiseki[v - 1] = i
	v = l[v - 1]
	i += 1
saisyo = kiseki[v - 1]
kuri = i - saisyo
if saisyo > k:
	print(kiseki.index(k) + 1)
else:
	amari = (k - saisyo) % kuri
	print(kiseki.index(amari + saisyo) + 1)


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


(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())
arr = list(map(int, input().split()))
i = 1
n = 0
visited = {i: n}
while k > 0:
	n += 1
	k -= 1
	i = arr[i - 1]
	if i in visited:
		break
	visited[i] = n
if k == 0:
	print(i)
else:
	k %= n - visited[i]
	while k > 0:
		k -= 1
		i = arr[i - 1]
	print(i)


(n, k) = map(int, input().split())
A = [int(v) - 1 for v in input().split()]
memo = {}
p = 0
for i in range(k):
	if p in memo:
		itvl = i - memo[p]
		rest = (k - i - 1) % itvl
		for j in range(rest + 1):
			p = A[p]
		print(p + 1)
		exit()
	else:
		memo[p] = i
	p = A[p]
print(p + 1)


(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) = map(int, input().split())
a = list(map(int, input().split()))
x = 1
l = [1]
f = [1] * n
f[0] = 0
for i in range(k):
	x = a[x - 1]
	if f[x - 1]:
		l.append(x)
		f[x - 1] = 0
	else:
		break
y = l.index(x)
res = (k - y) % (len(l) - y) + y
print(l[res])