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:

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.
The first line of the input contains two integers $n$ and $q$ ($2 \le n \le 2 \cdot 10^5, 1 \le q \le 2 \cdot 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, \dots, p_n$ ($1 \le p_i &lt; 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 \le u_i, k_i \le 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.
9 6
1 1 1 3 5 3 5 7
3 1
1 5
3 4
7 3
1 8
1 9
3
6
8
-1
9
4
2 1
1
1 1
1
13 12
1 1 1 1 1 1 1 1 1 1 1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1 1
1
1
1
1
1
1
1
1
1
1
1
1
# template taken from https://github.com/cheran-senthil/PyRival/blob/master/templates/template.py

import os
import sys
from io import BytesIO, IOBase
import math
from heapq import heappop, heappush, heapify, heapreplace
from collections import defaultdict, deque, OrderedDict
from bisect import bisect_left, bisect_right
#from functools import lru_cache
#import re
#from timeit import timeit
mod = 1000000007
mod1 = 998244353
sys.setrecursionlimit(100090)
alpha = {'a': 0, 'b': 1, 'c': 2, 'd': 3, 'e': 4, 'f': 5, 'g': 6, 'h': 7, 'i': 8, 'j': 9, 'k': 10, 'l': 11, 'm': 12, 'n': 13, 'o': 14, 'p': 15, 'q': 16, 'r': 17, 's': 18, 't': 19, 'u': 20, 'v': 21, 'w': 22, 'x': 23, 'y': 24, 'z': 25}


def read():
    sys.stdin  = open('input.txt', 'r')  
    sys.stdout = open('output.txt', 'w') 

# ------------------------------------------- Algos --------------------------------------------------------
def primeFactors(n):
    arr = []
    l = 0
    while n % 2 == 0:
        arr.append(2)
        l += 1
        n = n // 2
    for i in range(3,int(math.sqrt(n))+1,2):
        while n % i== 0:
            arr.append(i)
            l += 1
            n = n // i
    if n > 2:
        arr.append(n)
        l += 1
    return arr
    #return l
def primeFactorsSet(n):
    s = set()
    while n % 2 == 0:
        s.add(2)
        n = n // 2
    for i in range(3,int(math.sqrt(n))+1,2):
        while n % i== 0:
            s.add(i)
            n = n // i
    if n > 2:
        s.add(n)
    return s
def sieve(n):
    res=[0 for i in range(n+1)]
    #prime=set([])
    prime=[]
    for i in range(2,n+1):
        if not res[i]:
            #prime.add(i)
            prime.append(i)
            for j in range(1,n//i+1):
                res[i*j]=1
    return prime
def isPrime(n) : # Check Prime Number or not 
    if (n <= 1) : return False
    if (n <= 3) : return True
    if (n % 2 == 0 or n % 3 == 0) : return False
    i = 5
    while(i * i <= n) : 
        if (n % i == 0 or n % (i + 2) == 0) : 
            return False
        i = i + 6
    return True
def countPrimesLessThanN(n):
    seen, ans = [0] * n, 0
    for num in range(2, n):
        if seen[num]: continue
        ans += 1
        seen[num*num:n:num] = [1] * ((n - 1) // num - num + 1)
    return ans
def gcd(x, y):
    return math.gcd(x, y)
def lcm(a,b):
    return (a // gcd(a,b))* b
def isBitSet(n,k):
    # returns the count of numbers up to N having K-th bit set.
    res = (n >> (k + 1)) << k
    if ((n >> k) & 1):
        res += n & ((1 << k) - 1)
    return res
def popcount(x):
    x = x - ((x >> 1) & 0x55555555)
    x = (x & 0x33333333) + ((x >> 2) & 0x33333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    return x & 0x0000007f
def modular_exponentiation(x, y, p):    #returns (x^y)%p
    res = 1
    x = x % p
    if (x == 0) :
        return 0
    while (y > 0) :
        if ((y & 1) == 1) :
            res = (res * x) % p
        y = y >> 1
        x = (x * x) % p
    return res
def nCr(n, r, p):    # returns nCr % p
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * pow(den,
            p - 2, p)) % p
def smallestDivisor(n):
    if (n % 2 == 0):
        return 2
    i = 3
    while(i * i <= n):
        if (n % i == 0):
            return i
        i += 2
    return n
def numOfDivisors(n):
    def pf(n):
        dic = defaultdict(int)
        while n % 2 == 0:
            dic[2] += 1
            n = n // 2
        for i in range(3,int(math.sqrt(n))+1,2):
            while n % i== 0:
                dic[i] += 1
                n = n // i
        if n > 2:
            dic[n] += 1
        return dic
    p = pf(n)
    ans = 1
    for item in p:
        ans *= (p[item] + 1)
    return ans
'''def SPF(spf, MAXN):
    spf[1] = 1
    for i in range(2, MAXN):
        spf[i] = i
    for i in range(4, MAXN, 2):
        spf[i] = 2
    for i in range(3, math.ceil(math.sqrt(MAXN))):
        if (spf[i] == i):
            for j in range(i * i, MAXN, i):
                if (spf[j] == j):
                    spf[j] = i'''
# A O(log n) function returning prime
# factorization by dividing by smallest
# prime factor at every step
def factorizationInLogN(x, spf):
    #ret = list()
    dic = defaultdict(int)
    while (x != 1):
        #ret.append(spf[x])
        dic[spf[x]] += 1
        x = x // spf[x]
    #return ret
    return dic

'''MAXN = 10000001
spf = [0 for i in range(MAXN)]

SPF(spf, MAXN)'''

class DisjointSetUnion:
    def __init__(self, n):
        self.parent = list(range(n))
        self.size = [1] * n
        self.num_sets = n

    def find(self, a):
        acopy = a
        while a != self.parent[a]:
            a = self.parent[a]
        while acopy != a:
            self.parent[acopy], acopy = a, self.parent[acopy]
        return a

    def union(self, a, b):
        a, b = self.find(a), self.find(b)
        if a == b:
            return False
        if self.size[a] < self.size[b]:
            a, b = b, a
        self.num_sets -= 1
        self.parent[b] = a
        self.size[a] += self. size[b]
        return True

    def set_size(self, a):
        return self.size[self.find(a)]

    def __len__(self):
        return self.num_sets
#a = sorted(range(n), key=arr.__getitem__)
'''def interact(a, b):
    print(f"? {a} {b}", flush = True)
    return int(input())'''
# -------------------------------------------------- code -------------------------------------------------
def lis():
    return [int(i) for i in input().split()]

def dfs(adj, size, i, res):
    res.append(i+1)
    size[i] = 1
    for j in adj[i]:
        size[i] += dfs(adj, size, j, res)

    return size[i]


def main():

    n,q = map(int, input().split())
    arr = [-1]+lis()

    adj = [[]for i in range(n)]

    for i in range(1, n):
        adj[arr[i]-1].append(i)

    size = [0 for i in range(n)]

    res = []

    dfs(adj, size, 0, res)

    dic = {}
    for i in range(n):
        dic[res[i]] = i

    for i in range(q):
        u,k = map(int, input().split())
        if k > size[u-1]:
            print(-1)

        else:
            print(res[dic[u]+k-1])


# ---------------------------------------------- region fastio ---------------------------------------------
BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

# -------------------------------------------------- end region ---------------------------------------------

if __name__ == "__main__":
    #read()
    main()