#include <bits/stdc++.h>
using namespace std;
const long double M = 144115188075855872;
long long k = 1, g = 0, a[200100];
vector<long long> v[200100];
map<int, bool> vis;
map<int, int> m, mm, mmm;
void DFS(int x) {
  vis[x] = true;
  for (auto i : v[x])
    if (!vis[i]) {
      g++;
      k++;
      m[i] = k;
      mm[k] = i;
      DFS(i);
    }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  long long n, q, x, y;
  cin >> n >> q;
  for (long long i = 2; i <= n; i++) {
    cin >> a[i];
    v[a[i]].push_back(i);
    mmm[a[i]]++;
  }
  for (int i = n; i >= 2; i--) {
    mmm[a[i]] += mmm[i];
  }
  m[1] = 1;
  mm[1] = 1;
  DFS(1);
  for (int i = 0; i < q; i++) {
    cin >> x >> y;
    if (y - 1 > mmm[x]) {
      cout << -1 << endl;
      ;
      continue;
    }
    cout << mm[y + m[x] - 1] << endl;
  }
}
