#include <bits/stdc++.h>
using namespace std;
const double pi = acos(-1.0);
template <typename T, typename U>
inline void amin(T &x, U y) {
  if (y < x) x = y;
}
template <typename T, typename U>
inline void amax(T &x, U y) {
  if (x < y) x = y;
}
using namespace std;
vector<int> adj[200010];
int sz[200010];
int que[200010];
int pos[200010];
int ind = 0;
void dfs(int u) {
  que[ind] = u;
  pos[u] = ind;
  ind++;
  sz[u] = 1;
  for (int i = 0; i < adj[u].size(); ++i) {
    int v = adj[u][i];
    dfs(v);
    sz[u] += sz[v];
  }
}
int main() {
  int n, q;
  cin >> n >> q;
  int v;
  for (int u = 2; u <= n; ++u) {
    cin >> v;
    adj[v].push_back(u);
  }
  for (int i = 1; i <= n; ++i) {
    sort(adj[i].begin(), adj[i].end());
  }
  dfs(1);
  while (q--) {
    int u, k;
    cin >> u >> k;
    if (k > sz[u])
      cout << "-1\n";
    else {
      cout << (que[pos[u] + k - 1]) << "\n";
    }
  }
  return 0;
}
