#include <bits/stdc++.h>
using namespace std;
int n, q, t;
vector<int> g[200005];
int h[200005], in[200005], out[200005];
void dfs(int a) {
  in[a] = ++t;
  h[t] = a;
  for (int i : g[a]) {
    if (i != a) {
      dfs(i);
    }
  }
  out[a] = t;
}
void Solve() {
  int x;
  cin >> n >> q;
  for (int i = 2; i <= n; i++) {
    cin >> x;
    g[x].push_back(i);
  }
  dfs(1);
  int a, b;
  for (int i = 1; i <= q; i++) {
    cin >> a >> b;
    if (out[a] - in[a] + 1 < b)
      cout << -1 << "\n";
    else
      cout << h[in[a] + b - 1] << "\n";
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  Solve();
  return 0;
}
