#include <bits/stdc++.h>
using namespace std;
int vis[200005], n, dp[200005], mp[200005], q;
set<int> G[200005];
vector<int> v;
void dfs(int u) {
  mp[u] = v.size();
  v.push_back(u);
  dp[u] = 1;
  for (int ve : G[u]) {
    dfs(ve);
    dp[u] += dp[ve];
  }
}
int main() {
  cin >> n >> q;
  for (int i = 2; i <= n; i++) {
    int a;
    cin >> a;
    G[a].insert(i);
  }
  dfs(1);
  for (int i = 0; i < q; i++) {
    int y, k;
    cin >> y >> k;
    if (dp[y] < k)
      printf("-1\n");
    else {
      int joss = mp[y] + k - 1;
      printf("%d\n", v[joss]);
    }
  }
}
