#include <bits/stdc++.h>
using namespace std;
void setIO() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
}
long long n, q;
vector<long long> adj[200010];
long long tt = 0;
vector<long long> tin, tout, tour;
void dfs(long long x = 0, long long par = -1) {
  tin[x] = tt;
  tour.push_back(x);
  for (long long& c : adj[x]) {
    if (c != par) {
      ++tt;
      dfs(c, x);
    }
  }
  tout[x] = tt;
}
signed main() {
  setIO();
  {
    cin >> n >> q;
    long long p;
    for (long long i = 1; i < n; ++i) {
      cin >> p;
      p--;
      adj[i].push_back(p);
      adj[p].push_back(i);
    }
    for (long long i = 0; i < n; ++i) {
      sort(adj[i].begin(), adj[i].end());
    }
    tin.resize(n);
    tout.resize(n);
    tour.reserve(n);
    dfs();
  }
  long long u, k, subSize;
  while (q--) {
    cin >> u >> k;
    u--, k--;
    subSize = tout[u] - tin[u] + 1;
    if (k >= subSize) {
      cout << "-1\n";
      continue;
    }
    cout << tour[k + tin[u]] + 1 << '\n';
  }
}
