#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
vector<int> adj[N];
int vis[N];
vector<int> ans;
vector<int> des;
int dfs(int s) {
  vis[s] = 1;
  ans.push_back(s);
  int c = 1;
  for (int i = 0; i < adj[s].size(); i++) {
    if (vis[adj[s][i]] == 0) {
      c += dfs(adj[s][i]);
    }
  }
  des[s] = c;
  return c;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n, q;
  ans.clear();
  memset(vis, 0, sizeof(vis));
  cin >> n >> q;
  for (int i = 2; i <= n; i++) {
    int x;
    cin >> x;
    adj[x].push_back(i);
  }
  for (int i = 1; i <= n; i++) sort(adj[i].begin(), adj[i].end());
  vector<int> b(N);
  des.resize(N);
  int x = dfs(1);
  for (int i = 0; i < ans.size(); i++) {
    b[ans[i]] = i;
  }
  while (q--) {
    int u, k;
    cin >> u >> k;
    int ind = b[u];
    if (des[u] >= k)
      cout << ans[ind + k - 1] << endl;
    else
      cout << "-1" << endl;
  }
  return 0;
}
