#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 17;
int n, q, ver[maxn], st[maxn], ft[maxn];
vector<int> g[maxn];
void dfs(int v = 0, int p = -1) {
  static int time = 0;
  st[v] = time;
  ver[time++] = v;
  for (auto u : g[v]) dfs(u, v);
  ft[v] = time;
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> n >> q;
  for (int i = 1, p; i < n; i++) {
    cin >> p;
    g[p - 1].push_back(i);
  }
  dfs();
  while (q--) {
    int v, pos;
    cin >> v >> pos;
    v--, pos--;
    if (st[v] + pos >= ft[v])
      cout << "-1\n";
    else
      cout << ver[st[v] + pos] + 1 << '\n';
  }
}
