#include <bits/stdc++.h>
using namespace std;
long long n;
vector<long long> parent(200005);
vector<vector<long long> > children(200005);
vector<long long> limit(200005);
vector<long long> number(200005);
vector<long long> soldier(200005);
long long step = 0;
long long cur;
void dfs(long long f) {
  long long len = children[f].size();
  step++;
  number[f] = step;
  soldier[step] = f;
  for (long long i = 0; i < len; ++i) {
    long long to = children[f][i];
    dfs(to);
    if (i == len - 1) limit[f] = cur;
  }
  if (len == 0) {
    cur = step;
    limit[f] = number[f];
  }
}
void solve() {
  long long q;
  cin >> n >> q;
  for (long long i = 2; i <= n; ++i) {
    cin >> parent[i];
    children[parent[i]].push_back(i);
  }
  dfs(1);
  limit[1] = cur;
  long long u, k;
  for (int i = 0; i < q; ++i) {
    cin >> u >> k;
    if (limit[u] - number[u] + 1 < k)
      cout << -1 << '\n';
    else
      cout << soldier[number[u] + k - 1] << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(nullptr);
  cout.tie(nullptr);
  long long t = 1;
  for (long long www = 1; www <= t; ++www) solve();
  return 0;
}
