#include <bits/stdc++.h>
using namespace std;
const long long N = 1e6 + 2;
const long long MOD = 1e9 + 7;
const long long Inf = MOD * MOD;
const long double eps = 1e-7;
const long long dx[] = {1, 0, 0, 0};
const long long dy[] = {0, 1, 1, -1};
long long n, q, a, b, Sub[N], Par[N], Ind[N], timer = 0, tt = 1;
vector<int> M;
vector<int> adj[N];
void dfs(int u, int par) {
  M.push_back(u);
  for (auto x : adj[u]) {
    if (x != par) {
      dfs(x, u);
    }
  }
  Sub[par] += Sub[u] + 1;
}
void Solve() {
  scanf("%lld%lld", &n, &q);
  for (int i = 2; i <= n; ++i) {
    scanf("%lld", &Par[i]);
    adj[Par[i]].push_back(i);
    adj[i].push_back(Par[i]);
  }
  dfs(1, 0);
  for (int i = 0; i < M.size(); ++i) {
    Ind[M[i]] = i;
  }
  while (q--) {
    long long u, k;
    scanf("%lld%lld", &u, &k);
    --k;
    if (k > Sub[u]) {
      puts("-1");
      continue;
    }
    printf("%d\n", M[Ind[u] + k]);
  }
}
int main() {
  while (tt--) {
    ++timer;
    Solve();
    puts("");
  }
}
