#include <bits/stdc++.h>
using namespace std;
vector<int> tree[200001];
int dfs(int node, vector<int>& visitOrder, int* subtreeSize) {
  visitOrder.push_back(node);
  subtreeSize[node] = 0;
  for (vector<int>::iterator iter = tree[node].begin();
       iter != tree[node].end(); iter++) {
    subtreeSize[node] += dfs((*iter), visitOrder, subtreeSize);
  }
  return subtreeSize[node] + 1;
}
int main() {
  int n = 0, q = 0;
  cin >> n >> q;
  for (int i = 1; i < n; i++) {
    int p = 0;
    cin >> p;
    tree[p].push_back(i + 1);
  }
  vector<int> visitOrder;
  int subtreeSize[200001];
  int pos[200001];
  dfs(1, visitOrder, subtreeSize);
  for (int i = 0; i < visitOrder.size(); i++) {
    pos[visitOrder[i]] = i;
  }
  for (int i = 0; i < q; i++) {
    int u = 0, k = 0;
    cin >> u >> k;
    if (k > subtreeSize[u] + 1) {
      cout << -1 << endl;
    } else {
      cout << visitOrder[pos[u] + k - 1] << endl;
    }
  }
  return 0;
}
