#include <bits/stdc++.h>
using namespace std;
void fast() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
}
vector<int> vis(200005, 0);
vector<long long> ans, v[200005], ch(200005, 1);
void dfs(int s, int u) {
  vis[s] = 1;
  ans.push_back(s);
  for (long long i = 0; i < v[s].size(); ++i)
    if (vis[v[s][i]] == 0) dfs(v[s][i], s);
  ch[u] += ch[s];
}
int main() {
  fast();
  int n, q;
  cin >> n >> q;
  for (int i = 2; i <= n; ++i) {
    int t;
    cin >> t;
    v[t].push_back(i);
  }
  dfs(1, 0);
  vector<long long> m(200005, 0);
  for (int i = 0; i < n; ++i) m[ans[i]] = i + 1;
  while (q--) {
    int x, y;
    cin >> x >> y;
    if (y > ch[x])
      cout << -1 << '\n';
    else
      cout << ans[m[x] + y - 2] << '\n';
  }
}
