PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#LCA0000018. Hành trình dịch chuyển (Teleporter)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Hành trình dịch chuyển (Teleporter)

Teleporter

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are nn towns labeled 11 through nn. Town ii has exactly one teleporter that sends you to town AiA_i.

You start in town 11. Which town will you occupy after using a teleporter exactly KK times?

The number KK can be enormous, and your journey may revisit towns.

Input

  • The first line contains n,Kn,K.
  • The second line contains nn integers A1,…,AnA_1,\ldots,A_n.

Output

Print one integer: the final town.

Subtasks

  • Subtask 1 (20 points): n≤30n\le30; 2≤n≤2⋅1052\le n\le2\cdot10^5; 1≤K≤10181\le K\le10^{18}; 1≤Ai≤n1\le A_i\le n.
  • Subtask 2 (30 points): n≤1000n\le1000; 2≤n≤2⋅1052\le n\le2\cdot10^5; 1≤K≤10181\le K\le10^{18}; 1≤Ai≤n1\le A_i\le n.
  • Subtask 3 (50 points): 2≤n≤2⋅1052\le n\le2\cdot10^5; 1≤K≤10181\le K\le10^{18}; 1≤Ai≤n1\le A_i\le n.

Examples

Input

4 5
3 2 4 1

Output

4

Explanation

The route is 1o3o4o1o3o41 o3 o4 o1 o3 o4. After five teleports you are in town 44.