#include <bits/stdc++.h>
using namespace std;
int N, Q;
vector<int> G[200000], order, size;
int dfs(int u) {
  order.push_back(u);
  if (G[u].size() == 0) {
    size[u] = 1;
    return 1;
  }
  for (int i = 0; i < G[u].size(); i++) size[u] += dfs(G[u][i]);
  ++size[u];
  return size[u];
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin >> N >> Q;
  for (int n = 1; n < N; n++) {
    int superior;
    cin >> superior, --superior;
    G[superior].push_back(n);
  }
  size.assign(N, 0);
  dfs(0);
  vector<int> index(N);
  for (int i = 0; i < N; i++) index[order[i]] = i;
  for (int q = 0; q < Q; q++) {
    int u, k;
    cin >> u >> k, --u, --k;
    int pos = index[u] + k;
    if (k < size[u])
      cout << order[pos] + 1 << endl;
    else
      cout << -1 << endl;
  }
}
