#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
int n, q, p, cnt;
vector<int> G[N];
int seq[N], len[N], mp[N];
int dfs(int u) {
  seq[++cnt] = u, len[u] = 1, mp[u] = cnt;
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    len[u] += dfs(v);
  }
  return len[u];
}
int main() {
  cin >> n >> q;
  int u, k;
  for (int i = 2; i <= n; i++) {
    cin >> p;
    G[p].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    sort(G[i].begin(), G[i].end());
  }
  dfs(1);
  while (q--) {
    cin >> u >> k;
    if (k > len[u])
      cout << -1 << endl;
    else
      cout << seq[mp[u] + k - 1] << endl;
  }
  return 0;
}
