#include <bits/stdc++.h>
using namespace std;
vector<set<long long>> g;
vector<long long> be;
vector<long long> en;
long long t = 0;
vector<long long> tim;
void dfs(long long s) {
  t++;
  be[s] = t;
  tim[t] = s;
  for (auto it : g[s]) {
    dfs(it);
  }
  en[s] = t;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, q;
  cin >> n >> q;
  g.resize(n + 1);
  be.resize(n + 1);
  en.resize(n + 1);
  tim.resize(n + 1);
  for (long long i = 2; i <= n; i++) {
    long long p;
    cin >> p;
    g[p].insert(i);
  }
  dfs(1);
  while (q--) {
    long long u, k;
    cin >> u >> k;
    if (k > en[u] - be[u] + 1)
      cout << -1 << "\n";
    else
      cout << tim[be[u] + k - 1] << "\n";
  }
  return 0;
}
