#include <bits/stdc++.h>
using namespace std;
int n, q, a, b, k, t, has, idx[200005], si[200005];
vector<int> v, arr[200005];
void dfs(int a) {
  v.push_back(a);
  si[a] = 1;
  for (int i = 0; i < arr[a].size(); i++) {
    int k = arr[a][i];
    dfs(k);
    si[a] += si[k];
  }
}
int main() {
  cin >> n >> q;
  for (int i = 2; i <= n; i++) {
    cin >> a;
    arr[a].push_back(i);
  }
  dfs(1);
  for (int i = 0; i < v.size(); i++) idx[v[i]] = i;
  for (int i = 1; i <= q; i++) {
    cin >> a >> b;
    if (b > si[a])
      cout << "-1" << endl;
    else
      cout << v[idx[a] + b - 1] << endl;
  }
}
