#include <bits/stdc++.h>
using namespace std;
const int N = 2e5;
int ans[N], tin[N], tout[N], pos[N];
vector<int> tree[N];
vector<int> command;
void dfs(int v) {
  tin[v] = command.size();
  for (int j = 0; j < tree[v].size(); j++) {
    command.push_back(tree[v][j]);
    dfs(tree[v][j]);
  }
  tout[v] = command.size();
}
int main() {
  int n, q, t;
  cin >> n >> q;
  for (int i = 1; i < n; i++) {
    cin >> t;
    tree[t - 1].push_back(i);
  }
  command.push_back(0);
  dfs(0);
  for (int i = 0; i < q; i++) {
    int ind, u, k;
    cin >> u >> k;
    ind = tin[u - 1] + k - 2;
    if (ind >= n) {
      ans[i] = -2;
      continue;
    }
    ind = command[ind];
    if (tin[ind] < tin[u - 1] || tout[ind] > tout[u - 1])
      ans[i] = -2;
    else
      ans[i] = ind;
  }
  for (int i = 0; i < q; i++) cout << ans[i] + 1 << endl;
}
