#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> graph;
vector<int> visited;
vector<int> out;
vector<int> res;
vector<int> rev_res;
void dfs_rec_util(int u) {
  rev_res[u] = res.size();
  res.push_back(u);
  visited[u] = true;
  for (int v : graph[u])
    if (!visited[v]) dfs_rec_util(v);
  out[u] = res.size();
}
void dfs_rec(int s) { dfs_rec_util(s); }
int main() {
  int n, q;
  cin >> n >> q;
  visited = vector<int>(n, false);
  out = vector<int>(n);
  rev_res = vector<int>(n);
  graph = vector<vector<int>>(n);
  for (int i = 1; i < n; i++) {
    int p;
    cin >> p;
    graph[--p].push_back(i);
  }
  dfs_rec(0);
  vector<int> sol(q);
  for (int i = 0; i < q; i++) {
    int u, k;
    cin >> u >> k;
    --u;
    --k;
    int idx = rev_res[u];
    if (idx + k < out[u]) {
      sol[i] = res[idx + k] + 1;
    } else {
      sol[i] = -1;
    }
  }
  for (int el : sol) cout << el << endl;
  return 0;
}
