#include <bits/stdc++.h>
using namespace std;
const int N = 200002;
vector<vector<int> > adj;
int vis[N], st[N], sizes[N], c = 0;
std::vector<int> e;
void dfs(int i) {
  vis[i] = 1;
  e.push_back(i);
  st[i] = e.size() - 1;
  for (auto p : adj[i]) {
    if (!vis[p]) {
      dfs(p);
    }
  }
  sizes[i] = e.size() - 1 - st[i] + 1;
}
int main() {
  int n, q;
  cin >> n >> q;
  adj.resize(n);
  for (int i = 0; i < n - 1; i++) {
    int p;
    cin >> p;
    p--;
    adj[p].push_back(i + 1);
  }
  memset(vis, 0, sizeof(vis));
  dfs(0);
  for (int i = 0; i < q; i++) {
    int u, k;
    cin >> u >> k;
    u--;
    if (k > sizes[u])
      cout << "-1\n";
    else {
      cout << e[st[u] + k - 1] + 1 << "\n";
    }
  }
}
