#include <bits/stdc++.h>
using namespace std;
const int N_MAX = 250001, LOG_N = 20, Q_MAX = 3e5 + 1;
int N, Q;
int lg[N_MAX];
int st[LOG_N][N_MAX];
void SetInput(string name)
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
(void)!freopen((name + ".in").c_str(), "r", stdin);
(void)!freopen((name + ".out").c_str(), "w", stdout);
}
void ReadInput()
{
cin >> N >> Q;
for(int i = 1, x; i <= N; i++)
{
cin >> x;
st[0][i] = x;
}
}
void Precalc()
{
lg[1] = 0;
for(int i = 2; i <= N + 1; i++)
lg[i] = lg[(i >> 1)] + 1;
for(int i = 1, lgN = lg[N]; i <= lgN; i++)
for(int j = 1; j <= N; j++)
st[i][j] = st[i-1][st[i-1][j]];
}
void Solve()
{
int p, nrSt, temp;
while(Q--)
{
cin >> p >> nrSt;
while(nrSt != 0)
{
temp = lg[nrSt];
p = st[temp][p];
nrSt -= (1 << temp);
}
cout << p << '\n';
}
}
int main()
{
SetInput("stramosi");
ReadInput();
Precalc();
Solve();
return 0;
}