#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int n, m, L[N], R[N];
vector<int> q, g[N];
void dfs(int v) {
  sort(g[v].begin(), g[v].end());
  L[v] = q.size();
  q.push_back(v);
  for (auto to : g[v]) dfs(to);
  R[v] = q.size();
}
int main() {
  scanf("%d%d", &n, &m);
  for (int to = 2; to <= n; ++to) {
    int v;
    scanf("%d", &v);
    g[v].push_back(to);
  }
  dfs(1);
  for (int i = 0; i < m; ++i) {
    int x, k;
    scanf("%d%d", &x, &k);
    printf("%d\n", R[x] - L[x] < k ? -1 : q[L[x] + k - 1]);
  }
  return 0;
}
