#include <bits/stdc++.h>
using namespace std;
int n, q, a[200001], d[200001], dd[200001], kids[200001], t = 1;
vector<int> ke[200001];
void dfs(int u) {
  d[u] = t;
  dd[t++] = u;
  for (int i = 0; i < ke[u].size(); i++) {
    int v = ke[u][i];
    if (d[v] == 0) dfs(v);
  }
}
int main() {
  cin >> n >> q;
  for (int i = 1; i <= n; i++) kids[i] = 1;
  for (int v = 2; v <= n; v++) {
    cin >> a[v];
    ke[a[v]].push_back(v);
  }
  for (int i = n; i >= 2; i--) kids[a[i]] += kids[i];
  dfs(1);
  for (int i = 1; i <= q; i++) {
    int u, v;
    cin >> u >> v;
    if (v <= kids[u])
      cout << dd[d[u] - 1 + v] << endl;
    else
      cout << "-1\n";
  }
}
