#include <bits/stdc++.h>
using namespace std;
vector<long long> adj[200001];
vector<long long> v;
long long vis[200001];
map<long long, long long> mp;
long long cnt[200001];
void dfs(int node) {
  vis[node] = 1;
  v.push_back(node);
  mp[node] = v.size() - 1;
  cnt[node] = 1;
  for (int i = 0; i < adj[node].size(); i++) {
    int child = adj[node][i];
    if (vis[child] == 0) {
      dfs(child);
      cnt[node] += cnt[child];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n, q;
  cin >> n >> q;
  for (int i = 2; i <= n; i++) {
    int x;
    cin >> x;
    adj[i].push_back(x);
    adj[x].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    sort(adj[i].begin(), adj[i].end());
  }
  dfs(1);
  while (q--) {
    int u, k;
    cin >> u >> k;
    if (k > cnt[u])
      cout << "-1" << endl;
    else {
      int index = mp[u];
      cout << v[index + k - 1] << endl;
    }
  }
}
