#include <bits/stdc++.h>
using namespace std;
int n, q;
vector<int> v[200010];
int in[200010];
int out[200010];
vector<int> ord;
int indx = 0;
void dfsorder(int nod) {
  ord.push_back(nod);
  in[nod] = indx;
  indx++;
  for (int i = 0; i < v[nod].size(); i++) {
    dfsorder(v[nod][i]);
  }
  out[nod] = indx;
}
int main() {
  cin >> n >> q;
  for (int i = 2; i <= n; i++) {
    int a, b;
    cin >> a;
    v[a].push_back(i);
  }
  dfsorder(1);
  for (int i = 0; i < q; i++) {
    int a, b;
    cin >> a >> b;
    if (b > out[a] - in[a]) {
      cout << -1 << endl;
      continue;
    } else
      cout << ord[in[a] + b - 1] << endl;
  }
  return 0;
}
