#include <bits/stdc++.h>
using namespace std;
int const N = 2e5 + 2;
vector<int> g[N];
int s[N], ne[N], f[N];
int dfs(int x, int& un) {
  s[un] = x;
  f[x] = un;
  int res = 0;
  for (int i = 0; i < g[x].size(); i++) {
    ne[g[x][i]] = dfs(g[x][i], ++un);
    res += ne[g[x][i]];
  }
  return res + 1;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  int n, q, p;
  cin >> n >> q;
  for (int i = 2; i < n + 1; i++) {
    cin >> p;
    g[p].push_back(i);
  }
  int unn = 1;
  ne[1] = dfs(1, unn);
  int u, k;
  for (int i = 0; i < q; i++) {
    cin >> u >> k;
    if (ne[u] < k)
      cout << -1 << '\n';
    else
      cout << s[f[u] + k - 1] << '\n';
  }
}
