#include <bits/stdc++.h>
using namespace std;
int N, Q, u, v, k, ans = 0;
vector<vector<int>> adj;
bool visited[200005];
map<int, int> Steps, Node, child;
void dfs(int node) {
  if (visited[node]) {
    return;
  }
  child[node] = 1;
  visited[node] = true;
  ans++;
  Steps[node] = ans;
  Node[ans] = node;
  for (auto i : adj[node]) {
    dfs(i);
    child[node] += child[i];
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin >> N >> Q;
  adj = vector<vector<int>>(N + 1);
  int idx;
  for (int i = 2; i <= N; i++) {
    cin >> idx;
    adj[idx].push_back(i);
  }
  dfs(1);
  for (int i = 0; i < Q; i++) {
    cin >> idx >> k;
    if (child[idx] >= k) {
      cout << Node[Steps[idx] + k - 1] << endl;
    } else {
      cout << -1 << endl;
    }
  }
  return 0;
}
