#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3fLL;
const int MAX = 2e5 + 10;
vector<int> g[MAX];
vector<int> E, D, pos;
int cnt = -1;
void euler_tour(int v, int at = 0) {
  E.push_back(v);
  D[v] = at;
  pos[v] = ++cnt;
  for (auto u : g[v]) {
    euler_tour(u, at + 1);
  }
}
struct segtree {
  int n;
  vector<int> seg;
  segtree(vector<int> &V) {
    n = V.size();
    seg.assign(2 * n, INF);
    for (int i = 0; i < n; i++) seg[i + n] = D[V[i]];
    for (int i = n - 1; i >= 0; i--) seg[i] = min(seg[i << 1], seg[i << 1 | 1]);
  }
  int query(int l, int r) {
    int ans = INF;
    for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
      if (l & 1) ans = min(ans, seg[l++]);
      if (r & 1) ans = min(ans, seg[--r]);
    }
    return ans;
  }
};
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  int N, Q;
  cin >> N >> Q;
  D.assign(N, 0);
  pos.assign(N, -1);
  for (int i = 1; i < N; i++) {
    int x;
    cin >> x;
    x--;
    g[x].push_back(i);
  }
  for (int i = 0; i < N; i++) sort(g[i].begin(), g[i].end());
  euler_tour(0);
  segtree st(E);
  while (Q--) {
    int u, k;
    cin >> u >> k;
    u--;
    k--;
    if (!k)
      cout << u + 1 << '\n';
    else {
      if (pos[u] + k < N && st.query(pos[u] + 1, pos[u] + k + 1) > D[u])
        cout << E[pos[u] + k] + 1 << '\n';
      else
        cout << -1 << '\n';
    }
  }
  return 0;
}
