#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> adj(200002, vector<int>());
vector<bool> vis(200002, false);
vector<int> in(200002, 0), out(200002, 0), in1(200002, 0);
int timer = 0, timer1 = 0;
void dfs(int node) {
  vis[node] = true;
  in[node] = timer1++;
  in1[node] = timer++;
  for (auto child : adj[node]) {
    if (!vis[child]) {
      dfs(child);
    }
  }
  out[node] = timer++;
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 2; i <= n; i++) {
    int p;
    cin >> p;
    adj[i].push_back(p);
    adj[p].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    sort(adj[i].begin(), adj[i].end());
  }
  dfs(1);
  vector<pair<int, int>> v;
  for (int i = 1; i <= n; i++) {
    v.push_back({in[i], i});
  }
  sort(v.begin(), v.end());
  vector<int> arr(n, 0);
  for (int i = 0; i < n; i++) arr[i] = v[i].second;
  while (q--) {
    int u, k;
    cin >> u >> k;
    if (in[u] + k - 1 >= n)
      cout << -1 << "\n";
    else {
      if (in1[arr[in[u] + k - 1]] < out[u])
        cout << arr[in[u] + k - 1] << "\n";
      else
        cout << -1 << "\n";
    }
  }
  return 0;
}
