#include <bits/stdc++.h>
using namespace std;
int64_t ans, n, k, m, q, y, mark[200006], p[200006], s[200006], no[200006];
vector<int> v[200006];
void dfs(int x) {
  mark[x] = 1;
  no[x] = y;
  s[y++] = x;
  sort(v[x].begin(), v[x].end());
  for (auto i : v[x])
    if (!mark[i]) {
      dfs(i);
      p[x] += p[i];
    }
  p[x] += 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  for (int i = 2; i <= n; i++) {
    cin >> k;
    v[k].push_back(i);
  }
  dfs(1);
  cout << endl;
  int64_t d;
  while (q--) {
    cin >> d >> k;
    if (p[d] < k) {
      cout << "-1\n";
      continue;
    }
    cout << s[no[d] + k - 1] << endl;
  }
  return 0;
}
