#include <bits/stdc++.h>
using namespace std;
vector<int> v[200005];
int num[200005];
int s[200005];
int t[200005];
int co = 1;
int dfs(int pos) {
  s[co] = pos;
  t[pos] = co++;
  int number = 0;
  for (int i = 0; i < v[pos].size(); i++) {
    number += dfs(v[pos][i]);
  }
  num[pos] = number;
  number++;
  return number;
}
int main() {
  std::ios::sync_with_stdio(false);
  int n, q;
  cin >> n >> q;
  int pre;
  for (int i = 2; i <= n; i++) {
    cin >> pre;
    v[pre].push_back(i);
  }
  dfs(1);
  int u, k;
  while (q--) {
    cin >> u >> k;
    if (num[u] + 1 < k) {
      cout << -1 << endl;
    } else {
      cout << s[t[u] + k - 1] << endl;
    }
  }
}
