#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 5;
int mark[maxn], t[2 * maxn], p[maxn][3], p2[maxn];
vector<int> yal[maxn];
vector<int> ans;
int c = 1;
void dfs(int now) {
  ans.push_back(now);
  mark[now] = 1;
  t[c] = now;
  c++;
  for (int i = 0; i < yal[now].size(); i++) {
    if (!mark[yal[now][i]]) dfs(yal[now][i]);
  }
  t[c] = now;
  c++;
  return;
}
int32_t main() {
  int n, q;
  cin >> n >> q;
  for (int i = 2; i <= n; i++) {
    int a;
    cin >> a;
    yal[a].push_back(i);
  }
  dfs(1);
  for (int i = 1; i <= 2 * n; i++) {
    if (p[t[i]][1])
      p[t[i]][2] = i;
    else
      p[t[i]][1] = i;
  }
  for (int i = 0; i < n; i++) p2[ans[i]] = i;
  for (int i = 0; i < q; i++) {
    int u, k;
    cin >> u >> k;
    if (p2[u] + k - 1 >= n)
      cout << -1 << endl;
    else if (p[ans[p2[u]]][1] <= p[ans[p2[u] + k - 1]][1] and
             p[ans[p2[u]]][2] >= p[ans[p2[u] + k - 1]][2])
      cout << ans[p2[u] + k - 1] << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
