#include <bits/stdc++.h>
using namespace std;
set<int> v[200005];
bool vis[200005];
int count1[200005];
int u, k;
int c = 1, ans;
int no[200005];
int yes[200005];
void dfs(int u) {
  count1[u] = 1;
  no[u] = c;
  yes[c] = u;
  vis[u] = true;
  for (auto it = v[u].begin(); it != v[u].end(); it++) {
    if (!vis[*it]) {
      c++;
      vis[*it] = true;
      dfs(*it);
      count1[u] += count1[*it];
    }
  }
}
int main() {
  int n, q;
  cin >> n >> q;
  for (int i = 2; i <= n; i++) {
    int a;
    cin >> a;
    v[a].insert(i);
  }
  memset(vis, false, sizeof(vis));
  memset(yes, false, sizeof(yes));
  memset(count1, 0, sizeof(count1));
  dfs(1);
  while (q--) {
    cin >> u >> k;
    if (count1[u] < k) {
      cout << -1 << endl;
    } else {
      ans = no[u] + k - 1;
      cout << yes[ans] << endl;
    }
  }
}
