#include <bits/stdc++.h>
using namespace std;
int n, q, a, k, b, ans, curr = 0;
vector<int> pos;
vector<int> cnt;
vector<int> v;
vector<vector<int> > adj;
void dfs(int w) {
  v[curr] = w;
  pos[w] = curr++;
  for (int c : adj[w]) {
    dfs(c);
  }
  cnt[w] = curr - 1;
}
int main() {
  int t = 1;
  while (t--) {
    cin >> n >> q;
    adj.resize(n);
    for (long long int i = 0; i < n - 1; i += 1) {
      cin >> a;
      adj[a - 1].push_back(i + 1);
    }
    pos.resize(n);
    cnt.resize(n);
    v.resize(n);
    curr = 0;
    dfs(0);
    for (long long int i = 0; i < q; i += 1) {
      cin >> a >> k;
      a--;
      k--;
      k += pos[a];
      if (k <= cnt[a]) {
        ans = v[k] + 1;
      } else {
        ans = -1;
      }
      cout << ans << endl;
    }
  }
}
