#include <bits/stdc++.h>
using namespace std;
long long int n, q, pos[200007], sz[200007];
vector<long long int> adj[200007];
vector<long long int> d;
void dfs(long long int x, long long int p) {
  sz[x] = 1;
  pos[x] = (long long int)d.size();
  d.push_back(x);
  for (long long int i : adj[x]) {
    if (i == p) continue;
    dfs(i, x);
    sz[x] += sz[i];
  }
  return;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n >> q;
  for (long long int i = 2; i <= n; ++i) {
    long long int x;
    cin >> x;
    adj[x].push_back(i);
    adj[i].push_back(x);
  }
  dfs(1, -1);
  while (q--) {
    long long int x, y;
    cin >> x >> y;
    if (pos[x] + y - 1 >= (long long int)d.size() || y > sz[x]) {
      cout << "-1\n";
    } else
      cout << d[pos[x] + y - 1] << '\n';
  }
  return 0;
}
