#include <bits/stdc++.h>
std :: ifstream fin("stramosi.in");
int tree[19][250005];
int main() {
std :: ios_base :: sync_with_stdio(0);
int n, Q;
fin >> n >> Q;
int i;
for (i = 1; i <= n; ++ i)
fin >> tree[0][i];
short j;
for (j = 1; (1 << j) <= n; ++ j)
for (i = 1; i <= n; ++ i)
tree[j][i] = tree[j - 1][tree[j - 1][i]];
int stramos, last_bit, ans;
std :: ofstream fout("stramosi.out");
while (Q) {
-- Q;
fin >> ans >> stramos;
while (stramos) {
last_bit = std :: __lg((stramos ^ (stramos - 1) + 1));
ans = tree[last_bit][ans];
stramos -= (1 << last_bit);
}
fout << ans << '\n';
}
fin.close();
fout.close();
return 0;
}