#include <bits/stdc++.h>
using namespace std;
set<long long> g[200005];
long long in[200005];
long long out[200005];
long long timer;
map<long long, long long> order;
vector<long long> v;
void dfs(long long u, long long& l) {
  v.push_back(u);
  order[u] = l;
  l++;
  in[u] = timer++;
  for (auto to : g[u]) {
    dfs(to, l);
  }
  out[u] = timer++;
}
signed main() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 2; i <= n; i++) {
    long long x;
    cin >> x;
    g[x].insert(i);
  }
  long long l = 0;
  dfs(1, l);
  while (m--) {
    long long start, k;
    cin >> start >> k;
    long long index = order[start];
    index += k;
    index--;
    if (index >= (long long)v.size()) {
      cout << -1 << '\n';
    } else {
      long long i2 = order[v[index]];
      if (in[v[index]] >= in[start] && out[v[index]] <= out[start])
        cout << v[index] << '\n';
      else
        cout << -1 << '\n';
    }
  }
}
