{$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;
procedure work;
var i,j,p,k:longint;
begin
for i:=1 to ct do
begin
for j:=1 to n do
begin
p:=s[i-1,j];
s[i,j]:=s[i-1,p];
end;
end;
end;
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);
work;
for i:=1 to m do
begin
readln(fi,a,b);
vl:=a;
while b>0 do
begin
ct:=0;
while (1 shl ct) <= b do
inc(ct);
dec(ct);
b:=b-(1 shl ct);
vl:=s[ct,vl];
end;
writeln(fo,vl);
end;
close(fo);
end.