#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
vector<int> arr[N];
int c, num[N], st[N], ed[N];
void dfs(int x) {
  num[c] = x;
  st[x] = c++;
  for (int i = 0; i < arr[x].size(); i++) dfs(arr[x][i]);
  ed[x] = c;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, q, p, u, k;
  cin >> n >> q;
  for (int i = 2; i <= n; i++) {
    cin >> p;
    arr[p].push_back(i);
  }
  for (int i = 1; i <= n; i++) sort(arr[i].begin(), arr[i].end());
  dfs(1);
  while (q--) {
    cin >> u >> k;
    if (ed[u] - st[u] >= k)
      cout << num[st[u] + k - 1] << endl;
    else
      cout << -1 << endl;
  }
  return 0;
}
