#include <bits/stdc++.h>
using namespace std;
vector<long long int> G[200001];
vector<long long int> fullans;
bool visited[200001];
long long int no_nodes[200001];
long long int start_tree[200001];
int c;
int tc = 0;
int dfs(int root) {
  tc++;
  int c = 1;
  visited[root] = true;
  fullans.push_back(root);
  start_tree[root] = tc;
  for (int i = 0; i < G[root].size(); i++) {
    if (visited[G[root][i]] == false) {
      if (no_nodes[G[root][i]] == -1) {
        no_nodes[G[root][i]] = dfs(G[root][i]);
        c += no_nodes[G[root][i]];
      } else
        c += no_nodes[G[root][i]];
    }
  }
  return c;
}
int main() {
  long long int n, q, start, k, m;
  cin >> n >> q;
  fullans.push_back(-1);
  for (int i = 1; i <= n; i++) visited[i] = false;
  for (int i = 0; i <= n; i++) no_nodes[i] = -1;
  for (int i = 2; i <= n; i++) {
    cin >> m;
    G[m].push_back(i);
  }
  no_nodes[1] = dfs(1);
  for (int i = 0; i < q; i++) {
    cin >> start >> k;
    if (no_nodes[start] < k)
      cout << "-1"
           << "\n";
    else {
      cout << fullans[start_tree[start] + k - 1];
      cout << "\n";
    }
  }
}
