#include <bits/stdc++.h>
using namespace std;
const int maxn = 200010;
int n, q;
int clk = 0, ord = 0;
int frog[maxn], g[maxn], dfa[maxn], dfb[maxn], dfn[maxn << 1];
vector<int> E[maxn];
void dfs(int u) {
  dfa[u] = ++clk;
  dfn[clk] = u;
  frog[++ord] = u;
  g[u] = ord;
  int v;
  int siz = E[u].size();
  for (int i = 0; i < siz; i++) {
    v = E[u][i];
    dfs(v);
  }
  dfb[u] = ++clk;
  dfn[clk] = u;
}
void judge(int u, int k) {
  k--;
  if (k == 0) {
    printf("%d\n", u);
    return;
  }
  int cnt = dfb[u] - dfa[u];
  if ((cnt - 1) / 2 < k) {
    printf("-1\n");
    return;
  }
  int ans = frog[g[u] + k];
  printf("%d\n", ans);
}
int main() {
  scanf("%d%d", &n, &q);
  int v;
  for (int i = 2; i <= n; i++) {
    scanf("%d", &v);
    E[v].push_back(i);
  }
  dfs(1);
  int x, y;
  for (int i = 1; i <= q; i++) {
    scanf("%d%d", &x, &y);
    judge(x, y);
  }
  return 0;
}
