#include <bits/stdc++.h>
using namespace std;
const long long int mod = 1e9 + 7;
const long long int N = 200005;
const long long int inf = 1e9;
vector<long long int> g[N];
long long int s[N], e[N], tt, ver[N];
void dfs(long long int u) {
  s[u] = ++tt;
  ver[tt] = u;
  for (long long int v : g[u]) {
    dfs(v);
  }
  e[u] = tt;
}
signed main() {
  ios ::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  if (0) {
    freopen("inp.txt", "r", stdin);
  }
  long long int n, q;
  cin >> n >> q;
  for (long long int i = 2; i <= n; i++) {
    long long int p;
    cin >> p;
    g[p].emplace_back(i);
  }
  for (long long int i = 1; i <= n; i++) sort(g[i].begin(), g[i].end());
  dfs(1);
  while (q--) {
    long long int u, k;
    cin >> u >> k;
    if (e[u] - s[u] + 1 < k) {
      cout << "-1" << '\n';
    } else
      cout << ver[s[u] + k - 1] << '\n';
  }
  return 0;
}
