- 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 points numbered , the -th of which flows to point in one second. Maija's initial position is 1. There will be queries numbered of the following type: find Maija's position seconds after dropping to the river. Note that the river might have loops and dead ends.
Input
The first line contains two integers and . The second line contains integers . The third line contains integers .
Output
Print the answers to the queries on a single line.
Constraints
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