#include <bits/stdc++.h>
using namespace std;
vector<set<long long> > g;
vector<long long> used;
map<long long, long long> m1, m2, c;
long long cnt = 0, pos = 0, loh = 0, gay = 0;
void DFS(long long v) {
  cnt++;
  m1[cnt] = v;
  m2[v] = cnt;
  used[v] = 1;
  for (auto u : g[v]) {
    if (!used[u]) {
      DFS(u);
    }
  }
  c[v] = cnt - m2[v];
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long l;
  long long q;
  long long n;
  cin >> n >> q;
  g.resize(n);
  used.resize(n);
  for (long long i = 1; i < n; i++) {
    long long k;
    cin >> k;
    k--;
    g[k].insert(i);
  }
  DFS(0);
  for (long long i = 0; i < q; i++) {
    cin >> l >> loh;
    l--;
    if (c[l] + 1 < loh) {
      cout << -1 << endl;
    } else
      cout << m1[m2[l] + loh - 1] + 1 << endl;
  }
}
