#include <bits/stdc++.h>
using namespace std;
long long int v, e;
vector<long long int> adjlist[200179];
vector<long long int> mark(200179, -1);
vector<long long int> sol;
long long int prelen[200179];
long long int postlen[200179];
long long int p = 1;
bool f(long long int x, long long int y) { return x < y; }
void dfs(long long int u) {
  mark[u] = 1;
  prelen[u] = p;
  p++;
  sol.push_back(u);
  for (long long int i = 0; i < adjlist[u].size(); i++) {
    long long int x = adjlist[u][i];
    if (mark[x] == -1) {
      dfs(x);
    }
  }
  postlen[u] = p;
}
int main() {
  ios_base::sync_with_stdio(0);
  cin >> v;
  long long int n;
  cin >> n;
  for (long long int i = 2; i <= v; i++) {
    long long int x, y;
    cin >> x;
    adjlist[x].push_back(i);
  }
  for (long long int i = 1; i <= v; i++) {
    sort(adjlist[i].begin(), adjlist[i].end(), f);
  }
  dfs(1);
  for (long long int i = 0; i < n; i++) {
    long long int u, x;
    cin >> u >> x;
    if (postlen[u] - prelen[u] < x) {
      cout << "-1" << endl;
    } else {
      cout << sol[prelen[u] + x - 2] << endl;
    }
  }
  return 0;
}
