#include <bits/stdc++.h>
using namespace std;
template <class c>
struct rge {
  c b, e;
};
template <class c>
rge<c> range(c i, c j) {
  return rge<c>{i, j};
}
template <class c>
auto dud(c* x) -> decltype(cerr << *x, 0);
template <class c>
char dud(...);
struct debug {
  ~debug() { cerr << endl; }
  template <class c>
  typename enable_if<sizeof dud<c>(0) != 1, debug&>::type operator<<(c i) {
    cerr << boolalpha << i;
    return *this;
  }
  template <class c>
  typename enable_if<sizeof dud<c>(0) == 1, debug&>::type operator<<(c i) {
    return *this << range(begin(i), end(i));
  }
  template <class c, class b>
  debug& operator<<(pair<b, c> d) {
    return *this << "(" << d.first << ", " << d.second << ")";
  }
  template <class c>
  debug& operator<<(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it) *this << ", " + 2 * (it == d.b) << *it;
    return *this << "]";
  }
};
long long mod = 1e9 + 7;
int INF = 1e9;
long long INF64 = 1e18;
long long binpow(long long a, long long b, long long m) {
  a %= m;
  long long res = 1;
  while (b > 0) {
    if (b & 1) {
      res = res * a % m;
    }
    a = a * a % m;
    b >>= 1;
  }
  return res;
}
vector<vector<int>> adj(2e5 + 5);
vector<int> ord;
vector<int> pos(2e5 + 5);
vector<int> ending(2e5 + 5);
void dfs(int node, int par) {
  pos[node] = ord.size();
  ord.push_back(node);
  for (int i : adj[node]) {
    if (i == par) continue;
    dfs(i, node);
  }
  ending[node] = ord.size();
}
void test_case(int tnum) {
  int n, q;
  cin >> n >> q;
  for (int i = 2; i <= n; i++) {
    int u;
    cin >> u;
    adj[u].push_back(i);
    adj[i].push_back(u);
  }
  dfs(1, -1);
  for (int i = 0; i < q; i++) {
    int u, k;
    cin >> u >> k;
    if (pos[u] + k - 1 >= ending[u]) {
      cout << -1 << '\n';
    } else {
      cout << ord[pos[u] + k - 1] << '\n';
    }
  }
}
int main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(false);
  int t = 1;
  for (int i = 1; i <= t; i++) {
    test_case(t);
  }
}
