#include <bits/stdc++.h>
using namespace std;
int n, q, a[2 * 100005], b[2 * 100005], c[2 * 100005], k = 1;
vector<int> gr[2 * 100005];
void dfs(int x, int ft) {
  a[k] = x;
  b[x] = k;
  c[k]++;
  k++;
  for (int i = 0; i < gr[x].size(); i++) {
    int u = gr[x][i];
    if (u != ft) {
      dfs(u, x);
      c[b[x]] += c[b[u]];
    }
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n >> q;
  for (int i = 0; i < n - 1; i++) {
    int x;
    cin >> x;
    gr[i + 2].push_back(x);
    gr[x].push_back(i + 2);
  }
  dfs(1, 0);
  while (q--) {
    int s, f;
    cin >> s >> f;
    if (c[b[s]] >= f)
      cout << a[b[s] + f - 1] << endl;
    else
      cout << -1 << endl;
  }
}
