#include <bits/stdc++.h>
using namespace std;
int n, q, a, b;
vector<int> v[200005];
int st[200005], en[200005], tim[200005], t = 0;
void dfs(int s) {
  st[s] = t;
  tim[t++] = s;
  for (int i = 0; i < v[s].size(); i++) dfs(v[s][i]);
  en[s] = t;
}
int main() {
  cin >> n >> q;
  for (int i = 2; i <= n; i++) {
    cin >> a;
    v[a].push_back(i);
  }
  dfs(1);
  while (q--) {
    cin >> a >> b;
    if (b <= en[a] - st[a])
      cout << tim[st[a] + b - 1];
    else
      cout << -1;
    cout << endl;
  }
  return 0;
}
