CSES - Aalto Competitive Programming 2024 - wk4 - Wed - Bathhouse
  • Time limit: 2.00 s
  • Memory limit: 512 MB

After a long and exhausting day of work, Maija decides to visit the local bathhouse. There she finds a gently flowing artificial river filled with pleasantly hot water. Feigning to pass out, she flops to the river and floats where the currents take her.

The artificial river can be modeled as n points numbered 1,2,\dots,n, the i-th of which flows to point p_i in one second. Maija's initial position is 1. There will be q queries numbered 1,2,\dots,q of the following type: find Maija's position a_i seconds after dropping to the river. Note that the river might have loops and dead ends.

Input

The first line contains two integers n and q. The second line contains n integers p_1,\,p_2,\dots,\,p_n. The third line contains q integers a_1,\,a_2,\dots,\,a_q.

Output

Print the answers to the queries on a single line.

Constraints

  • 1 \leq n, q \leq 10^5
  • 1 \leq p_i \leq n
  • 0 \leq a_i \leq 10^{12}

Example 1

Input:

5 5
3 3 4 3 3
12 4 11 0 15

Output:

4 4 3 1 3

Example 2

Input:

10 12
9 4 1 4 2 10 3 7 6 8 
24 7 22 29 0 12 7 0 16 10 99999999999 1000000000000

Output:

10 1 9 9 1 7 1 1 6 10 8 9