#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
int n, q;
int p[200010];
vector<int> G[200010];
int in[200010], out[200010];
int pos[200010];
void dfs(int cur, int &lev) {
  in[cur] = lev;
  for (int nxt : G[cur]) {
    lev++;
    dfs(nxt, lev);
  }
  out[cur] = lev;
}
int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  cin >> n >> q;
  for (int i = 0; i < n - 1; i++) {
    cin >> p[i];
    p[i]--;
    G[p[i]].emplace_back(i + 1);
  }
  int lev = 0;
  dfs(0, lev);
  for (int i = 0; i < n; i++) {
    pos[in[i]] = i;
  }
  for (int i = 0; i < q; i++) {
    int u, k;
    cin >> u >> k;
    u--;
    k--;
    if (in[u] + k > out[u])
      cout << -1 << endl;
    else
      cout << pos[in[u] + k] + 1 << endl;
  }
  return 0;
}
