#include <bits/stdc++.h>
using namespace std;
int c1[200003];
int d[200003];
void dfs(vector<bool> &b, int v, vector<int> &cur, vector<int> a[]) {
  b[v] = true;
  d[v] = cur.size();
  cur.push_back(v);
  c1[v] = 1;
  for (int i = 0; i < a[v].size(); i++) {
    dfs(b, a[v][i], cur, a);
    c1[v] += c1[a[v][i]];
  }
}
int main() {
  int n, q;
  cin >> n >> q;
  vector<int> a[n + 1];
  for (int i = 0; i < n - 1; i++) {
    int a1;
    cin >> a1;
    a[a1].push_back(i + 2);
  }
  vector<int> ans;
  vector<bool> c(n + 1);
  for (int i = 0; i <= n; i++) c[i] = false;
  dfs(c, 1, ans, a);
  while (q--) {
    int a1, b1;
    cin >> a1 >> b1;
    if (b1 > c1[a1]) {
      cout << "-1" << endl;
    } else {
      cout << ans[d[a1] + b1 - 1] << endl;
    }
  }
  return 0;
}
