#include <bits/stdc++.h>
using namespace std;
map<char, int> ma;
const int maxn = 2e5 + 100;
vector<int> vec[maxn];
int ans[maxn], pos[maxn], sum[maxn];
int t1 = 1;
void dfs(int fa) {
  ans[t1++] = fa;
  pos[fa] = t1 - 1;
  if (vec[fa].size() == 0) {
    sum[fa] = 1;
    return;
  }
  for (int i = 0; i < vec[fa].size(); i++) {
    dfs(vec[fa][i]);
    sum[fa] += sum[vec[fa][i]];
  }
  sum[fa]++;
}
int main(int argc, char *argv[]) {
  int n, t, temp, a, b;
  memset(sum, 0, sizeof(sum));
  cin >> n >> t;
  for (int i = 1; i <= n; i++) {
    vec[i].clear();
  }
  for (int i = 2; i <= n; i++) {
    cin >> temp;
    vec[temp].push_back(i);
  }
  dfs(1);
  cout << endl;
  for (int i = 1; i <= t; i++) {
    cin >> a >> b;
    int up = pos[a];
    if (b > sum[a]) {
      cout << -1 << endl;
    } else {
      cout << ans[b + up - 1] << endl;
    }
  }
  return 0;
}
