#include <bits/stdc++.h>
using namespace std;
vector<int> v;
vector<vector<int>> v1;
map<int, int> m;
map<int, int> m1;
int dfs(int i, int n) {
  v.push_back(i);
  m.insert({i, v.size() - 1});
  sort(v1[i].begin(), v1[i].end());
  int count = 1;
  for (int j = 0; j < v1[i].size(); j++) {
    count += dfs(v1[i][j], n);
  }
  m1.insert({i, count});
  return count;
}
int main() {
  int n, k;
  cin >> n >> k;
  for (int i = 0; i <= n; i++) {
    vector<int> vx;
    v1.push_back(vx);
  }
  for (int i = 2; i <= n; i++) {
    int val;
    cin >> val;
    v1[val].push_back(i);
  }
  dfs(1, n);
  for (int i = 0; i < k; i++) {
    int x, y;
    cin >> x >> y;
    int index = m.find(x)->second;
    if ((m1.find(x)->second) < y) {
      cout << -1 << endl;
    } else {
      cout << v[index + y - 1] << endl;
    }
  }
  return 0;
}
