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
# Code by B3D
# Love

from math import *
from collections import *
import io, os
import sys
from bisect import *
from heapq import *
 
MOD = 1000000007
# sys.setrecursionlimit(10**6)


def subinp():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("op1.txt", "w")

def subinp_1():
    sys.stdin = open("input.txt", "r")
    sys.stdout = open("op2.txt", "w")

def binpow(a, b, m):
    a %= m
    x = 1
    while b > 0:
        if b & 1:
            x = x * a % m
        a = a * a % m
        b >>= 1
    return x

 
 
def binser(arr, l, r, x):
    while l < r:
        mid = l + (r - l) // 2
        # print(l, r, mid)
 
        if arr[mid] == x:
            return mid
 
        elif arr[mid] < x:
            l = mid + 1
 
        else:
            r = mid - 1
 
    return mid
 
def lcm(a, b):
    return (a * b) // gcd(a, b)
 
def sod(n):
    l = list(str(n))
    s = 0
    for i in l:
        s += int(i)
    return s
 
 
def prime_factors(num):   
    l =[]
    if num % 2:
        l.append(2)
    while num % 2 == 0:  
        num = num / 2  
  
    for i in range(3, int(sqrt(num)) + 1, 2):  
        if not num % i:
            l.append(i)
        while num % i == 0:  
            num = num / i
    if num > 2:
        l.append(num)
    return l
 
 
def factmod(n, p):
 
    f = defaultdict(int)
    f[0] = 1
    for i in range(1, n + 1):
        f[i] = (f[i-1] * i) % MOD
 
    """
    res = 1
    while (n > 1):
        if (n//p) % 2:
            res = p - res
 
        res = res * f[n%p] % p
        n //= p
    """
 
    return f
 
 
 
def largestPower(n, p):
     
    # Initialize result
    x = 0
     
    # Calculate x = n/p + n/(p^2) + n/(p^3) + ....
    while (n):
        n //= p
        x += n
    return x
 
def modFact(n, p):
    if n >= p:
        return 0   
 
    result = 1
    for i in range(1, n + 1):
        result = (result * i) % p
 
    return result
 
def drec(x, y):
    if y == x + 1:
        return 'R'
    if y == x - 1:
        return 'L'
    if x < y:
        return 'D'
    return 'U'
 
def cellhash(x, y):
    return (x - 1) * m + y
 
 
def bins(l, x, n):
    i = bisect_left(l, x)
    if i < n:
        return i
    if i:
        return (i-1)
    else:
        return n

def cond(l):
    for i in range(len(l) - 1):
        if l[i] == str(int(l[i + 1]) - 1):
            return False
    return True

def isvowel(s):
    if s in list("aeiou"):
        return 1
    return 0

def countOdd(L, R):
 
    N = (R - L) // 2
 
    # if either R or L is odd
    if (R % 2 != 0 or L % 2 != 0):
        N += 1
 
    return N

def tst(A, B, C):
    return ((A|B) & (B|C) & (C|A))

def palcheck(n, s):
    i, j = 0, n - 1
    while i <= j:
        if s[i] == s[j]:
            return False
        i += 1
        j -= 1
    return True

def sakurajima(n):
    if n < 9:
        n = 10
    l = [0]

    for i in range(1, n + 1):
        if i % 2:
            l.append(i)
        else:
            l.append(2)

    for i in range(3, int(n ** 0.5) + 1, 2):
        if l[i] == i:
            for j in range(i * i, n + 1, i):
                if l[j] == j:
                    l[j] = i
    return l




def getfact(x):
    ret = []
    d = defaultdict(int)
    while x != 1:
        ret.append(spf[x] ** (d[spf[x]] + 1))
        d[spf[x]] += 1
        x = x // spf[x]
 
    return ret

def prchck(n):
    if n == 1:
        return False
    for i in range(2, int(sqrt(n)) + 1):
        if not n % i:
            return False
    return True

def ispal(s, n):
    for i in range(n // 2):
        if s[i] != s[n - i - 1]:
            return False
    return True


def bfs(src, dest, ajl, vis):
    q = deque([src])
    vis[src] = True
 
    while q:
        i = q.popleft()
        if i == dest:
            return True
        for j in ajl[i]:
            if not vis[j]:
                vis[j] = True
                q.append(j)
    return False


def sieve(n):
    if n < 9:
        n = 10
    l = [1] * (n + 1)
    for i in range(2, int(n ** 0.5) + 1):
        if l[i]:
            for j in range(i ** 2, n + 1, i):
                if j % i == 0:
                    l[j] = 0
    l[1] = 0
    return l

class DisjSet:
    def __init__(self, n):
        self.size = [1] * n
        self.parent = [i for i in range(n)]
  
 
    def find(self, x):
        if (self.parent[x] != x):
            self.parent[x] = self.find(self.parent[x])
  
        return self.parent[x]
  
 
    def union(self, x, y):
 
        xset = self.find(x)
        yset = self.find(y)
  
        if xset == yset:
            return
  
        if self.size[xset] < self.size[yset]:
            self.parent[xset] = yset
            self.size[yset] += self.size[xset]
  
        else:
            self.parent[yset] = xset
            self.size[xset] += self.size[yset]

def dfs(i, ajl, vis, l, x):
    vis[i] = True
    l[i] = x

    for j in ajl[i]:
        if not vis[j]:
            dfs(j, ajl, vis, l, x)

# spf = sakurajima(10 ** 5 + 1)
def checkpo3(N):
    while N > 0:

        if N % 3 == 2:
            return False
        N //= 3

    return True

def sumofdig(n):
    ans = 0
    s = str(n)
    for i in s:
        ans += int(i)
    return ans 

def convert(set):
    return [*set, ]

def ncr(n, r, p):
    num = den = 1
    for i in range(r):
        num = (num * (n - i)) % p
        den = (den * (i + 1)) % p
    return (num * binpow(den,
            p - 2, p)) % p

def modmult(a, b, m):
    return ((a %  m) * (b % m)) % m

def Divisors(n):
    i = 1
    ans = []
    while (i * i < n):
        if (n % i == 0):
            ans.append(i)
 
        i += 1
 
    for i in range(int(sqrt(n)), 0, -1):
        if (n % i == 0):
            ans.append(n // i)

    return ans

def euler_tour(n, ajl):
    s = []
    s.append(1)
    now = [1] * (n + 1)
    t = 1
    t1, t2 = [-1] * (n + 1), [-1] * (n + 1)
    v = []
    dp = [0] * (n + 1)

    for i in ajl:
        dp[i] += len(ajl[i]) - 1

    while s:
        i = s[-1]
        if t1[i] == -1:
            v.append(i)
            t1[i] = t
            t += 1
        if now[i] == len(ajl[i]):
            t2[i] = t
            t += 1
            s.pop()
        else:
            s.append(ajl[i][now[i]])
            now[i] += 1
        
    
    return v

"""
pow2 = [1]
# print(log2(10 ** 9))
for i in range(29):
    pow2.append(pow2[-1] * 2)
"""
# input = sys.stdin.readline
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
 
inp    = lambda:int(input())
strin  = lambda: input().strip()
strl   = lambda: list(input().rstrip("\r\n"))
strlst = lambda: list(map(str, input().split()))
mult   = lambda: map(int,input().strip().split())
mulf   = lambda: map(float,input().strip().split())
lstin  = lambda: list(map(int,input().strip().split()))
 
flush  = lambda: stdout.flush()
stdpr  = lambda x: stdout.write(str(x))


# Power comes in response to a need, not a desire.
 
# n = int(input())
# n, k = map(int, input().split())
# s = input()
# l = list(map(int, input().split()))
# memo = [[-1 for i in range(n + 1)] for j in range(2)]

def panda(src, n, l, ajl):
    vis = [False] * (n + 1)
    q = deque([src])
    vis[src] = True
    dp = [1] * (n + 1)
    l1 = []
    dp[1] += 1
 
    while q:
        i = q.popleft()
        l1.append(i)
        for j in ajl[i]:
            if not vis[j]:
                vis[j] = True
                q.append(j)

    while l1:
        x = l1.pop()
        if x > 2:
            dp[l[x - 1]] += dp[x]
    print(dp)

    return dp



t = 1
# t = int(input())
for _ in range(t):
    n, q = mult()
    ajl = defaultdict(list)
    l = [-1] + lstin()
    ajl[1].append(1)

    for i in range(1, n):
        ajl[l[i]].append(i + 1)
        ajl[i + 1].append(l[i])
    # print(ajl)

    dfa = []
    vis = [False] * (n + 2)
    dp = panda(1, n, l, ajl)

    dfa = euler_tour(n, ajl)
    # print(dfa)

    ind = defaultdict(int)
    # print(dp)

    for i in range(n):
        ind[dfa[i]] = i
    # print(ind)

    for i in range(q):
        u, k = mult()
        if dp[u] - 1 < k - 1:
            print(-1)
        else:
            print(dfa[ind[u] + k - 1])

    # sys.stdout.write(str(ans))
    # print("Case #" + str(_ + 1) + ": " + str(ans))