In this problem you will have to help Berland army with organizing their command delivery system.

There are n 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 a is the direct superior of officer b, then we also can say that officer b is a direct subordinate of officer a.

Officer x is considered to be a subordinate (direct or indirect) of officer y if one of the following conditions holds:

  * officer y is the direct superior of officer x; 
  * the direct superior of officer x is a subordinate of officer y. 



For example, on the picture below the subordinates of the officer 3 are: 5, 6, 7, 8, 9.

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 n vertices, in which vertex u corresponds to officer u. The parent of vertex u corresponds to the direct superior of officer u. The root (which has index 1) corresponds to the commander of the army.

Berland War Ministry has ordered you to give answers on q queries, the i-th query is given as (u_i, k_i), where u_i is some officer, and k_i is a positive integer.

To process the i-th query imagine how a command from u_i spreads to the subordinates of u_i. Typical DFS (depth first search) algorithm is used here.

Suppose the current officer is a and he spreads a command. Officer a chooses b — 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 a chooses the one having minimal index. Officer a gives a command to officer b. Afterwards, b uses exactly the same algorithm to spread the command to its subtree. After b finishes spreading the command, officer a chooses the next direct subordinate again (using the same strategy). When officer a cannot choose any direct subordinate who still hasn't received this command, officer a finishes spreading the command.

Let's look at the following example:

<image>

If officer 1 spreads a command, officers receive it in the following order: [1, 2, 3, 5 ,6, 8, 7, 9, 4].

If officer 3 spreads a command, officers receive it in the following order: [3, 5, 6, 8, 7, 9].

If officer 7 spreads a command, officers receive it in the following order: [7, 9].

If officer 9 spreads a command, officers receive it in the following order: [9].

To answer the i-th query (u_i, k_i), construct a sequence which describes the order in which officers will receive the command if the u_i-th officer spreads it. Return the k_i-th element of the constructed list or -1 if there are fewer than k_i elements in it.

You should process queries independently. A query doesn't affect the following queries.

Input

The first line of the input contains two integers n and q (2 ≤ n ≤ 2 ⋅ 10^5, 1 ≤ q ≤ 2 ⋅ 10^5) — the number of officers in Berland army and the number of queries.

The second line of the input contains n - 1 integers p_2, p_3, ..., p_n (1 ≤ p_i < i), where p_i is the index of the direct superior of the officer having the index i. The commander has index 1 and doesn't have any superiors.

The next q lines describe the queries. The i-th query is given as a pair (u_i, k_i) (1 ≤ u_i, k_i ≤ n), where u_i is the index of the officer which starts spreading a command, and k_i is the index of the required officer in the command spreading sequence.

Output

Print q numbers, where the i-th number is the officer at the position k_i in the list which describes the order in which officers will receive the command if it starts spreading from officer u_i. Print "-1" if the number of officers which receive the command is less than k_i.

You should process queries independently. They do not affect each other.

Example

Input

9 6
1 1 1 3 5 3 5 7
3 1
1 5
3 4
7 3
1 8
1 9


Output

3
6
8
-1
9
4
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

/**
 * E.Military Problem
 * 输入n个端点跟q次询问
 * 然后输入n-1个数,第i个数代表序号为(i+1)的端点的父节点
 * 接着输入q个询问,每个询问输入u跟k两个数,代表从u开始传播(前序遍历)的第k个数
 */
public class EMilitaryProblem {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt(), q = scan.nextInt();
        int[] father = new int[n + 1];
        for (int i = 2; i <= n; i++) {
            father[i] = scan.nextInt();
        }
        //初始化军官树
        Officers officerTree = new Officers(father);
        //开始询问
        List<Integer> target = officerTree.getPreOrder();
        int u, k;
        for (int i = 0; i < q; i++) {
            u = scan.nextInt();
            k = scan.nextInt();
            if (officerTree.getOfficer(u).getCount() < k) {
                System.out.println("-1");
            } else {
                System.out.println(target.get(officerTree.getOfficer(u).getOrder() + k - 1));
            }

        }
    }

    /**
     * 存放军官的树,存放一个数组维护所有节点.
     */
    static class Officers {

        private Node[] nodes;
        private List<Integer> preOrder;

        /**
         * 初始化,将树连通,统计,生成前序遍历结果
         *
         * @param fatherArray 从2开始,fatherArray[i]对应军官i的上级
         */
        Officers(int[] fatherArray) {
            nodes = new Node[fatherArray.length];
            nodes[1] = new Node(1);
            for (int i = 2; i < fatherArray.length; i++) {
                nodes[fatherArray[i]].addSon(nodes[i] = new Node(i));
            }
            preOrder = new ArrayList<>(fatherArray.length - 1);
            countNodeAndGenerateOrder(nodes[1]);
        }

        /**
         * 对每一个节点进行递归统计,顺便生成前序遍历的结果
         */
        private int countNodeAndGenerateOrder(Node nod) {
            nod.setOrder(preOrder.size());
            preOrder.add(nod.getIndex());
            int count = 1;
            for (Node node : nod.sons) {
                count += countNodeAndGenerateOrder(node);
            }
            nod.setCount(count);
            return count;
        }

        public List<Integer> getPreOrder() {
            return preOrder;
        }

        public Node getOfficer(int index) {
            return nodes[index];
        }

        /**
         * 节点
         */
        class Node {
            private int index;
            private int count;
            private int order;
            private List<Node> sons = new LinkedList<>();

            Node(int index) {
                this.index = index;
            }

            public void addSon(Node son) {
                sons.add(son);
            }

            public void setCount(int count) {
                this.count = count;
            }

            public int getIndex() {
                return index;
            }

            public int getCount() {
                return count;
            }

            public void setOrder(int order) {
                this.order = order;
            }

            public int getOrder() {
                return order;
            }


        }
    }
}
