#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, k, a[N], len[N], p, q, pos[N];
vector<int> child[N];
void dfs(int u) {
  a[k] = u;
  pos[u] = k++;
  for (int v : child[u]) {
    dfs(v);
  }
  len[u] = k - pos[u];
}
void init() {
  scanf("%d%d", &n, &q);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &p);
    child[p].push_back(i);
  }
  dfs(1);
  int u;
  while (q--) {
    scanf("%d%d", &u, &k);
    if (len[u] < k)
      puts("-1");
    else
      printf("%d\n", a[pos[u] + k - 1]);
  }
}
int main() {
  init();
  return 0;
}
