#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000 * 100 + 1;
const long long INF = 1e18;
const int MOD = 1000 * 1000 * 1000 + 7;
const int dx[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
vector<long long> s[200005], a;
vector<long long>::iterator it;
queue<int> q;
int h[200005] = {}, n, x;
int r, arr[200005], b[200005], cnt;
int qinsert(int node) {
  h[node] = 1;
  int cnt = 0;
  a.push_back(node);
  for (auto i : s[node]) {
    if (!h[i]) cnt += qinsert(i);
  }
  arr[node] = cnt + 1;
  return cnt + 1;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ;
  int i, j, z = 0, l, m, k, x, c, y, p = 0, sum = 0;
  cin >> n >> k;
  x = n;
  for (int i = (2); i <= (n); i++) {
    cin >> x;
    s[x].push_back(i);
  }
  qinsert(1);
  for (int i = (0); i <= (a.size() - 1); i++) b[a[i]] = i;
  for (int i = (0); i <= (k - 1); i++) {
    cin >> l >> c;
    if (arr[l] < c) {
      cout << -1 << endl;
    } else
      cout << a[b[l] + c - 1] << endl;
  }
}
