#include <bits/stdc++.h>
using namespace std;
vector<vector<long long>> graph;
vector<long long> tin, vt, sz;
long long timer;
void dfs(long long v, long long p = -1) {
  tin[v] = timer;
  vt[timer++] = v;
  long long size = 1;
  for (long long u : graph[v]) {
    if (u != p) {
      dfs(u, v);
      size += sz[u];
    }
  }
  sz[v] = size;
}
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long n, q;
  cin >> n >> q;
  graph.resize(n);
  tin.resize(n);
  vt.resize(n);
  sz.resize(n);
  for (long long i = 1; i < n; ++i) {
    long long p;
    cin >> p;
    graph[p - 1].push_back(i);
  }
  dfs(0);
  for (long long i = 0; i < q; ++i) {
    long long u, k;
    cin >> u >> k;
    --u;
    if (sz[u] < k) {
      cout << -1;
    } else {
      cout << vt[tin[u] + k - 1] + 1;
    }
    cout << "\n";
  }
  return 0;
}
