#include <bits/stdc++.h>
using namespace std;
vector<int> v[200005], ans;
int dp[200005];
map<int, int> mapp;
void dfs1(int node) {
  ans.push_back(node);
  for (auto it : v[node]) dfs1(it);
}
int dfs2(int node) {
  if (v[node].size() == 0) {
    return dp[node] = 1;
  }
  int anss = 1;
  for (auto it : v[node]) anss += dfs2(it);
  return dp[node] = anss;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  ;
  int x, y, n, m, ele;
  cin >> n >> m;
  for (long long i = 2; i < n + 1; i++) {
    cin >> ele;
    v[ele].push_back(i);
  }
  for (long long i = 1; i < n + 1; i++) sort(v[i].begin(), v[i].end());
  dfs1(1);
  dfs2(1);
  for (int i = 0; i < ans.size(); i++) {
    mapp[ans[i]] = i;
  }
  while (m--) {
    cin >> x >> y;
    if (dp[x] >= y) {
      cout << ans[mapp[x] + y - 1] << endl;
    } else
      cout << "-1\n";
  }
  return 0;
}
