#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 20;
int n, k, x, y, dfn[N], id[N], ed[N];
vector<int> G[N];
int sz = 0;
void dfs(int x) {
  dfn[x] = ++sz;
  id[sz] = x;
  for (int i = 0; i < G[x].size(); i++) {
    dfs(G[x][i]);
  }
  ed[x] = sz;
}
int main(void) {
  scanf("%d%d", &n, &k);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &x);
    G[x].push_back(i);
  }
  dfs(1);
  for (int i = 0; i < k; i++) {
    scanf("%d%d", &x, &y);
    int to = dfn[x] - 1 + y;
    if (to > ed[x])
      printf("-1\n");
    else
      printf("%d\n", id[to]);
  }
}
