#include <bits/stdc++.h>
using namespace std;
int timer = 0;
int in[200005], out[200005];
map<int, int> m;
vector<int> v[200005];
void dfs(int x) {
  in[x] = ++timer;
  m[timer] = x;
  for (int i = 0; i < v[x].size(); i++) {
    dfs(v[x][i]);
  }
  out[x] = timer;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int n, q;
  cin >> n >> q;
  for (int i = 2; i <= n; i++) {
    long long int x;
    cin >> x;
    v[x].push_back(i);
  }
  dfs(1);
  while (q--) {
    int x, y;
    cin >> x >> y;
    if (in[x] + y - 1 <= out[x]) {
      cout << m[in[x] + y - 1] << endl;
    } else
      cout << -1 << endl;
  }
  return 0;
}
