#include <bits/stdc++.h>
using namespace std;
void dfs(long long v, bool visited[], vector<long long> adj[],
         long long start[], long long end[], long long &timer,
         vector<long long> &seq) {
  seq.push_back(v);
  visited[v] = true;
  start[v] = timer;
  timer++;
  for (long long i = 0; i < adj[v].size(); i++) {
    if (!visited[adj[v][i]]) {
      dfs(adj[v][i], visited, adj, start, end, timer, seq);
    }
  }
  end[v] = timer;
  timer++;
}
int main() {
  long long n, q;
  cin >> n >> q;
  vector<long long> adj[n];
  long long parent[n];
  parent[0] = -1;
  for (long long i = 0; i < n - 1; i++) {
    long long x;
    cin >> x;
    parent[i + 1] = x - 1;
    adj[i + 1].push_back(x - 1);
    adj[x - 1].push_back(i + 1);
  }
  for (long long i = 0; i < n; i++) {
    sort(adj[i].begin(), adj[i].end());
  }
  long long start[n], end[n];
  bool visited[n];
  memset(visited, false, n * sizeof(bool));
  long long timer = 0;
  vector<long long> seq;
  dfs(0, visited, adj, start, end, timer, seq);
  long long pos[n];
  for (long long i = 0; i < n; i++) {
    pos[seq[i]] = i;
  }
  for (long long i = 0; i < q; i++) {
    long long u, k;
    cin >> u >> k;
    u--;
    long long x = pos[u];
    if (x + k - 1 >= n) {
      cout << -1 << endl;
    } else {
      long long y = seq[x + k - 1];
      if (start[y] >= start[u] && end[y] <= end[u]) {
        cout << y + 1 << endl;
      } else {
        cout << -1 << endl;
      }
    }
  }
}
