#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[200005];
vector<long long> ans, pos, last;
long long j = 0;
void dfs(long long x) {
  ans.push_back(x);
  pos[x] = j++;
  for (auto& i : adj[x]) {
    dfs(i);
  }
  last[x] = j - 1;
  return;
}
int32_t main() {
  long long n, q, val, k;
  cin >> n >> q;
  vector<long long> an[200005];
  vector<long long> v;
  pos.resize(n + 1);
  last.resize(n + 1);
  v.push_back(0);
  for (long long i = 0; i < n - 1; i++) {
    cin >> val;
    v.push_back(val);
  }
  for (long long i = 1; i <= n - 1; i++) {
    adj[v[i]].push_back(i + 1);
  }
  dfs(1);
  for (long long i = 0; i < q; i++) {
    long long u, k;
    cin >> u >> k;
    if (pos[u] + k - 1 <= last[u])
      cout << ans[pos[u] + k - 1] << endl;
    else
      cout << "-1" << endl;
  }
}
