#include <bits/stdc++.h>
using namespace std;
vector<vector<int>> officers(2e5);
vector<int> order;
vector<pair<int, int>> range(2e5);
void dfs(int i) {
  int st = order.size();
  order.push_back(i);
  for (auto x : officers[i]) dfs(x);
  int en = order.size();
  range[i] = make_pair(st, en - st);
}
int main() {
  int n, q, temp, temp1;
  cin >> n >> q;
  for (int i = 1; i < n; i++) {
    cin >> temp;
    officers[temp - 1].push_back(i);
  }
  dfs(0);
  for (int i = 0; i < q; i++) {
    cin >> temp >> temp1;
    if (range[temp - 1].second < temp1)
      cout << -1 << endl;
    else
      cout << order[range[temp - 1].first + temp1 - 1] + 1 << endl;
  }
}
