#include <bits/stdc++.h>
using namespace std;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int par[2 * 100005], sze[2 * 100005], vis[2 * 100005];
vector<long long int> adj[2 * 100005], order;
int dfs(int x) {
  vis[x] = 1;
  int cnt = 0;
  order.push_back(x);
  for (auto i : adj[x]) {
    if (!vis[i]) cnt += dfs(i);
  }
  sze[x] = cnt + 1;
  return cnt + 1;
}
int main() {
  int n, q;
  cin >> n >> q;
  par[1] = 1;
  for (int i = 2; i <= n; i++) {
    cin >> par[i];
    adj[par[i]].push_back(i);
  }
  dfs(1);
  map<int, int> m;
  for (int i = 0; i < order.size(); i++) {
    m[order[i]] = i;
  }
  while (q--) {
    int u, k;
    cin >> u >> k;
    if (sze[u] < k)
      cout << "-1" << '\n';
    else {
      cout << order[m[u] + k - 1] << '\n';
    }
  }
  return 0;
}
