#include <bits/stdc++.h>
using namespace std;
bool Finish_read;
template <class T>
inline void read(T &x) {
  Finish_read = 0;
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') {
      f = -1;
    }
    if (ch == EOF) {
      return;
    }
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
    x *= f;
    Finish_read = 1;
  }
}
template <class T>
inline void print(T x) {
  if (x / 10 != 0) {
    print(x / 10);
  }
  putchar(x % 10 + '0');
}
template <class T>
inline void writeln(T x) {
  if (x < 0) {
    putchar('-');
  }
  x = abs(x);
  print(x);
  putchar('\n');
}
template <class T>
inline void write(T x) {
  if (x < 0) {
    putchar('-');
  }
  x = abs(x);
  print(x);
  putchar(' ');
}
const int maxn = 200100;
long long int n, m;
long long int a[maxn], b[maxn];
long long int lang[maxn];
vector<int> Edge[maxn];
int now = 1;
void dfs(int x) {
  a[now++] = x;
  for (int i = 0; i < Edge[x].size(); i++) {
    lang[x]++;
    dfs(Edge[x][i]);
    lang[x] += lang[Edge[x][i]];
  }
}
void bbb() {
  for (int i = 1; i < now; i++) {
    b[a[i]] = i;
  }
}
int main() {
  read(n);
  read(m);
  memset(lang, 0, sizeof(lang));
  for (int i = 1; i < n; i++) {
    long long int x;
    read(x);
    Edge[x].push_back(i + 1);
  }
  for (int i = 1; i <= maxn; i++) {
    i = i;
  }
  dfs(1);
  bbb();
  int x, y;
  for (int i = 1; i <= m; i++) {
    read(x);
    read(y);
    if (y - 1 > lang[x]) {
      puts("-1");
    } else {
      writeln(a[b[x] + y - 1]);
    }
  }
  return 0;
}
