#include <bits/stdc++.h>
using namespace std;
set<int> s[200000 + 100];
int ar[200000 + 100];
int value[200000 + 100];
vector<int> v;
long long ncrp(long long n, long long r, long long p) {
  long long C[r + 1];
  memset(C, 0, sizeof(C));
  C[0] = 1;
  for (long long i = 1; i <= n; i++)
    for (long long j = min(i, r); j >= 1; j--) C[j] = (C[j] + C[j - 1]) % p;
  return C[r];
}
long long mod_exp(long long x, long long y, long long mm) {
  x %= mm;
  if (y == 0)
    return (1);
  else if (y % 2 == 0)
    return (mod_exp((x * x) % mm, y / 2, mm));
  else
    return ((x * mod_exp((x * x) % mm, (y - 1) / 2, mm)) % mm);
}
int dfs(int i) {
  v.push_back(i);
  ar[i] = 1;
  int p = 1;
  set<int>::iterator it;
  for (it = s[i].begin(); it != s[i].end(); it++) {
    if (ar[*it] == 0) p = p + dfs(*it);
  }
  value[i] = p;
  return p;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  cin >> n >> q;
  for (long long i = 2; i <= n; i++) {
    int p;
    cin >> p;
    s[i].insert(p);
    s[p].insert(i);
  }
  int p = dfs(1);
  int a[n + 1];
  for (long long i = 0; i < n; i++) a[v[i]] = i;
  for (long long i = 0; i < q; i++) {
    int u, k;
    cin >> u >> k;
    if (value[u] < k)
      cout << "-1\n";
    else
      cout << v[a[u] + k - 1] << "\n";
  }
  return 0;
}
