{$IFDEF NORMAL}
{$I-,OBJECTCHECKS-,Q-,R-,S-}
{$ENDIF NORMAL}
{$IFDEF DEBUG}
{$I+,OBJECTCHECKS-,Q+,R+,S-}
{$ENDIF DEBUG}
{$IFDEF RELEASE}
{$I-,OBJECTCHECKS-,Q-,R-,S-}
{$ENDIF RELEASE}
type matr=array[0..18,0..250000] of longint;
var fi,fo:text;
j,i,n,m,st,vl,a,b,ct:longint;
s : matr;
begin
assign(fi,'stramosi.in'); reset(fi);
assign(fo,'stramosi.out'); rewrite(fo);
readln(fi,n,m);
for i:=1 to n do
begin
read(fi,s[0,i]);
end;
st:=1;
while st<=n do
begin
st:=st shl 1;
inc(ct);
end;
dec(ct);
for i:=1 to ct do
for j:=1 to n do
s[i,j]:=s[i-1,s[i-1,j]];
for i:=1 to m do
begin
readln(fi,a,b);
while b>0 do
begin
ct:=0;
while (1 shl ct) <= b do
inc(ct);
dec(ct);
b:=b-(1 shl ct);
a:=s[ct,a];
end;
writeln(fo,a);
end;
close(fo);
end.