#include <bits/stdc++.h>
using namespace std;
using pi = pair<long long, long long>;
using vi = vector<long long>;
using vvi = vector<vector<long long> >;
const long long NUM = 1000030;
const long long N = 10000000;
vector<long long> lp, sieve;
vector<long long> pr;
void primefactor();
long long binpow(long long a, long long b);
long long binpow(long long a, long long b, long long mod);
long long gcd(long long a, long long b);
long long lcm(long long a, long long b);
bool comp(long long a, long long b);
long long inversemod(long long a, long long mod);
void calc_sieve();
void dfs(long long p, vi& visited, vi& visitorder, vi& visitstart, vi& visitend,
         vvi& edges) {
  visited[p] = 1;
  visitorder.push_back(p);
  visitstart[p] = (long long)(visitorder).size();
  for (long long i = 0; i < (long long)(edges[p]).size(); i++) {
    if (!visited[edges[p][i]]) {
      dfs(edges[p][i], visited, visitorder, visitstart, visitend, edges);
    }
  }
  visitend[p] = (long long)(visitorder).size();
}
void test() {
  long long n, q;
  cin >> n >> q;
  long long i;
  vi parent(n + 1);
  parent[1] = 1;
  vvi edges(n + 1);
  for (i = 1; i < n; i++) {
    cin >> parent[i + 1];
    edges[parent[i + 1]].push_back(i + 1);
  }
  for (i = 1; i <= n; i++) sort(edges[i].begin(), edges[i].end());
  vi visited(n + 1, 0), visitorder, visitstart(n + 1), visitend(n + 1);
  dfs(1, visited, visitorder, visitstart, visitend, edges);
  for (i = 0; i < q; i++) {
    long long a, b;
    cin >> a >> b;
    long long ele = visitend[a] - visitstart[a] + 1;
    if (b > ele) {
      cout << -1 << endl;
      continue;
    }
    cout << visitorder[visitstart[a] + b - 2] << endl;
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  long long t = 1;
  while (t--) test();
  return 0;
}
void calc_sieve() {
  sieve.resize(NUM + 1, 0);
  for (long long x = 2; x <= NUM; x++) {
    if (sieve[x]) continue;
    for (long long u = x; u <= NUM; u += x) {
      sieve[u] = x;
    }
  }
}
void primefactor() {
  lp.resize(N + 1, 0);
  for (long long i = 2; i <= N; ++i) {
    if (lp[i] == 0) {
      lp[i] = i;
      pr.push_back(i);
    }
    for (long long j = 0;
         j < (long long)pr.size() && pr[j] <= lp[i] && i * pr[j] <= N; ++j)
      lp[i * pr[j]] = pr[j];
  }
}
long long binpow(long long a, long long b) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a;
    a = a * a;
    b >>= 1;
  }
  return res;
}
long long binpow(long long a, long long b, long long mod) {
  long long res = 1;
  while (b > 0) {
    if (b & 1) res = (res * a) % mod;
    a = (a * a) % mod;
    b >>= 1;
  }
  return res % mod;
}
long long gcd(long long a, long long b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
long long lcm(long long a, long long b) { return ((a / gcd(a, b)) * b); }
bool comp(long long a, long long b) { return a > b; }
long long inversemod(long long a, long long mod) {
  return binpow(a, mod - 2, mod);
}
