#include <bits/stdc++.h>
using namespace std;
int n, q, x, temp = 1;
int mark[200020], a[200020], b[200020], c[200020], a2[200020];
vector<int> v[200020];
void dfs(int n) {
  if (mark[n] == 1) return;
  mark[n] = 1;
  a2[n] = temp;
  a[temp++] = n;
  for (int i = 0; i < v[n].size(); i++) dfs(v[n][i]);
}
int main() {
  cin >> n >> q;
  for (int i = 2; i <= n; i++) {
    cin >> b[i];
    v[b[i]].push_back(i);
  }
  dfs(1);
  for (int i = n; i >= 1; i--) {
    c[i] += 1;
    c[b[i]] += c[i];
  }
  while (q--) {
    int u, k;
    cin >> u >> k;
    if (c[u] < k)
      cout << "-1" << endl;
    else
      cout << a[a2[u] + k - 1] << endl;
  }
}
