#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
int sz[N];
int idx[N];
bool vis[N];
vector<int> g[N], v;
void Dfs(int Node) {
  vis[Node] = 1;
  sz[Node] = v.size();
  v.push_back(Node);
  for (int &i : g[Node]) {
    if (!vis[i]) Dfs(i);
  }
  sz[Node] = v.size() - sz[Node];
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.precision(10), cout << fixed;
  int n, q;
  cin >> n >> q;
  for (int i = 1, x; i < n; ++i) {
    cin >> x;
    x--;
    g[x].push_back(i);
  }
  Dfs(0);
  for (int i = 0; i < v.size(); ++i) idx[v[i]] = i;
  while (q--) {
    int u, k;
    cin >> u >> k;
    u--;
    k--;
    if (k + 1 > sz[u])
      cout << "-1\n";
    else
      cout << v[idx[u] + k] + 1 << '\n';
  }
  return 0;
}
