#include <bits/stdc++.h>
using namespace std;
const double h = 1e-6;
const int MAX_ = 100005;
inline long long int mul(long long int a, long long int b) {
  return (a * 1ll * b) % 1000000007;
}
inline long long int sub(long long int a, long long int b) {
  long long int c = a - b;
  if (c < 0) c += 1000000007;
  return c;
}
inline long long int add(long long int a, long long int b) {
  long long int c = a + b;
  if (c > 1000000007) c -= 1000000007;
  return c;
}
struct graph {
  vector<int> v;
  int b = 1, st, ed;
};
vector<int> df;
int pre = 1;
void fastdfs(graph G[], int n, int start) {
  if (G[start].v.size() == 0) {
    G[start].st = G[start].ed = pre - 1;
    return;
  }
  G[start].st = pre - 1;
  for (int i = 0; i < G[start].v.size(); i++) {
    df[pre++] = G[start].v[i];
    fastdfs(G, n, G[start].v[i]);
    G[start].b += G[G[start].v[i]].b;
  }
  G[start].ed = pre - 1;
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n, q, val;
  cin >> n >> q;
  graph G[n + 1];
  for (int i = 2; i <= n; i++) {
    cin >> val;
    G[val].v.push_back(i);
  }
  df.resize(n);
  df[0] = 1;
  fastdfs(G, n, 1);
  while (q--) {
    int x, k;
    cin >> x >> k;
    if (G[x].b < k)
      cout << -1 << "\n";
    else {
      cout << df[G[x].st + k - 1] << "\n";
    }
  }
  return 0;
}
