Problem: In this problem you will have to help Berland army with organizing their command delivery system.
There are officers in Berland army. The first officer is the commander of the army, and he does not have any superiors. Every other officer has exactly one direct superior. If officer is the direct superior of officer , then we also can say that officer is a direct subordinate of officer .
Officer is considered to be a subordinate (direct or indirect) of officer if one of the following conditions holds:
- officer is the direct superior of officer ;
- the direct superior of officer is a subordinate of officer .
For example, on the picture below the subordinates of the officer are: .
The structure of Berland army is organized in such a way that every officer, except for the commander, is a subordinate of the commander of the army.
Formally, let's represent Berland army as a tree consisting of vertices, in which vertex corresponds to officer . The parent of vertex corresponds to the direct superior of officer . The root (which has index ) corresponds to the commander of the army.
Berland War Ministry has ordered you to give answers on queries, the -th query is given as , where is some officer, and is a positive integer.
To process the -th query imagine how a command from spreads to the subordinates of . Typical DFS (depth first search) algorithm is used here.
Suppose the current officer is and he spreads a command. Officer chooses — one of his direct subordinates (i.e. a child in the tree) who has not received this command yet. If there are many such direct subordinates, then chooses the one having minimal index. Officer gives a command to officer . Afterwards, uses exactly the same algorithm to spread the command to its subtree. After finishes spreading the command, officer chooses the next direct subordinate again (using the same strategy). When officer cannot choose any direct subordinate who still hasn't received this command, officer finishes spreading the command.
Let's look at the following example:
If officer spreads a command, officers receive it in the following order: .
If officer spreads a command, officers receive it in the following order: .
If officer spreads a command, officers receive it in the following order: .
If officer spreads a command, officers receive it in the following order: .
To answer the -th query , construct a sequence which describes the order in which officers will receive the command if the -th officer spreads it. Return the -th element of the constructed list or -1 if there are fewer than elements in it.
You should process queries independently. A query doesn't affect the following queries.
Input Format: The first line of the input contains two integers and () — the number of officers in Berland army and the number of queries.
The second line of the input contains integers (), where is the index of the direct superior of the officer having the index . The commander has index and doesn't have any superiors.
The next lines describe the queries. The -th query is given as a pair () (), where is the index of the officer which starts spreading a command, and is the index of the required officer in the command spreading sequence.
Output Format: Print numbers, where the -th number is the officer at the position in the list which describes the order in which officers will receive the command if it starts spreading from officer . Print "-1" if the number of officers which receive the command is less than .
You should process queries independently. They do not affect each other.