#include <bits/stdc++.h>
using namespace std;
int dfs(std::vector<bool>& vis, int ci, vector<int>& v, vector<vector<int>>& list,unordered_map<int,int> & lenc){
vis.at(ci)=1;
v.push_back(ci);
int uji=-1;
int l=-1;
for(int i=0;i<(int)list.at(ci).size();i++){
if(vis.at(list.at(ci).at(i))==0){
l=1;
uji= dfs(vis,list.at(ci).at(i),v,list,lenc);
}
}
if(l==-1) {lenc.at(ci)=ci; return ci;}
lenc.at(ci)=uji;
return uji;
}
int main() {
int n,q;
scanf("%d%d",&n,&q);
vector<vector<int>> list(n+1);
for(int i=2;i<=n;i++){
int a;
scanf("%d",&a);
list.at(a).push_back(i);
list.at(i).push_back(a);
}
for(int i=1;i<=n;i++){
sort(list.at(i).begin(),list.at(i).end());
}
unordered_map<int,int> lenc;
vector<int> v;
std::vector<bool> vis(1+n, false);
dfs(vis,1,v,list,lenc);
unordered_map<int,int> m;
for(int i=0;i<(int)v.size();i++){
m[v[i]]=i;
}
while(q--){
int a,b;
cin>>a>>b;
int i1=m.at(a);
int i2=m.at(lenc.at(a));
if(i1+b-1>i2) printf("-1\n");
else printf("%d\n",v.at(i1+b-1));
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCBkZnMoc3RkOjp2ZWN0b3I8Ym9vbD4mIHZpcywgaW50IGNpLCB2ZWN0b3I8aW50PiYgdiwgIHZlY3Rvcjx2ZWN0b3I8aW50Pj4mIGxpc3QsdW5vcmRlcmVkX21hcDxpbnQsaW50PiAmIGxlbmMpewogICAgdmlzLmF0KGNpKT0xOwogICAgdi5wdXNoX2JhY2soY2kpOwogICAgaW50IHVqaT0tMTsKICAgIGludCBsPS0xOwogICAgZm9yKGludCBpPTA7aTwoaW50KWxpc3QuYXQoY2kpLnNpemUoKTtpKyspewogICAgICAgIGlmKHZpcy5hdChsaXN0LmF0KGNpKS5hdChpKSk9PTApewogICAgICAgICAgICBsPTE7CiAgICAgICAgdWppPSBkZnModmlzLGxpc3QuYXQoY2kpLmF0KGkpLHYsbGlzdCxsZW5jKTsKICAgICAgICB9CiAgICB9CiAgICBpZihsPT0tMSkge2xlbmMuYXQoY2kpPWNpOyByZXR1cm4gY2k7fQogICAgbGVuYy5hdChjaSk9dWppOwogICAgcmV0dXJuIHVqaTsKfQppbnQgbWFpbigpIHsKICAgIGludCBuLHE7CiAgICBzY2FuZigiJWQlZCIsJm4sJnEpOwogICAgdmVjdG9yPHZlY3RvcjxpbnQ+PiBsaXN0KG4rMSk7CiAgICBmb3IoaW50ICBpPTI7aTw9bjtpKyspewogICAgICAgIGludCBhOwogICAgICAgIHNjYW5mKCIlZCIsJmEpOwogICAgICAgIGxpc3QuYXQoYSkucHVzaF9iYWNrKGkpOwogICAgICAgIGxpc3QuYXQoaSkucHVzaF9iYWNrKGEpOwogICAgfQogICAgZm9yKGludCBpPTE7aTw9bjtpKyspewogICAgICAgIHNvcnQobGlzdC5hdChpKS5iZWdpbigpLGxpc3QuYXQoaSkuZW5kKCkpOwogICAgfQogICAgdW5vcmRlcmVkX21hcDxpbnQsaW50PiBsZW5jOwogICAgdmVjdG9yPGludD4gIHY7CiAgICBzdGQ6OnZlY3Rvcjxib29sPiB2aXMoMStuLCBmYWxzZSk7CiAgICBkZnModmlzLDEsdixsaXN0LGxlbmMpOwogICB1bm9yZGVyZWRfbWFwPGludCxpbnQ+IG07CgogICBmb3IoaW50IGk9MDtpPChpbnQpdi5zaXplKCk7aSsrKXsKICAgICAgIG1bdltpXV09aTsKICAgfQoKICAgd2hpbGUocS0tKXsKICAgICAgIGludCBhLGI7CiAgICAgICBjaW4+PmE+PmI7CiAgICAgICBpbnQgaTE9bS5hdChhKTsKICAgICAgIGludCBpMj1tLmF0KGxlbmMuYXQoYSkpOwogICAgICAgaWYoaTErYi0xPmkyKSBwcmludGYoIi0xXG4iKTsKICAgICAgIGVsc2UgcHJpbnRmKCIlZFxuIix2LmF0KGkxK2ItMSkpOwogICB9Cn0=