func_code_string: #include <bits/stdc++.h>   using namespace std;   const long long maxx = 1e9 + 7;   bool compare(const pair<long long, long long> &a,                const pair<long long, long long> &b) {     return a.first > b.first || (a.first == b.first && a.second < b.second);   }   long long inline power(long long a, long long b, long long p) {     a %= p;     long long ans = 1;     while (b > 0) {       if (b & 1) ans = (ans * a) % p;       a = (a * a) % p;       b >>= 1;     }     return ans;   }   long long inv(long long n, long long p) { return power(n, p - 2, p); }   bool inline isPrime(long long n) {     if (n <= 1) return false;     if (n <= 3) return true;     if (n % 2 == 0 || n % 3 == 0) return false;     for (long long i = 5; i * i <= n; i = i + 6)       if (n % i == 0 || n % (i + 2) == 0) return false;     return true;   }   template <class T>   void printv(T &v, long long n) {     if (n == -1) n = v.size();     for (long long i = 0; i < n; i++) cout << v[i] <<    ;     cout <<   n ;   }   const long long maxn = 2e5 + 5;   vector<long long> parent(maxn, 0);   vector<vector<long long> > v;   long long start;   vector<long long> pos(maxn);   vector<pair<long long, long long> > gap(maxn);   void dfs(long long node) {     start++;     pos[start] = node;     gap[node].first = start;     for (auto &x : v[node]) {       if (x == parent[node]) continue;       dfs(x);     }     gap[node].second = start;   }   void solve() {     long long n, q, u, k;     cin >> n >> q;     start = 0;     v.assign(n + 1, vector<long long>());     for (long long i = 1; i <= n - 1; i++) {       cin >> parent[i + 1];       v[i + 1].push_back(parent[i + 1]);       v[parent[i + 1]].push_back(i + 1);     }     for (auto &x : v) sort(x.begin(), x.end());     dfs(1);     for (long long i = 1; i <= q; i++) {       cin >> u >> k;       if (gap[u].second - gap[u].first + 1 < k) {         cout << -1 <<   n ;         continue;       }       cout << pos[((gap[u].first) + k - 1)] <<   n ;     }   }   int main() {     ios_base::sync_with_stdio(false);     cin.tie(NULL);     cout.tie(NULL);     long long test = 1;     while (test--) {       solve();     }   }   