{$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}
var fi,fo:text;
j,i,n,m,st,vl,a,b,ct:longint;
s:array[0..19,0..250000] of integer;
procedure work;
var i,j,p,k:longint;
begin
for i:=1 to ct do
begin
for j:=1 to n do
begin
s[i,j]:=s[i-1,s[i-1,j]];
end;
end;
end;
begin
assign(fi,'stramosi.in'); reset(fi);
assign(fo,'stramosi.out'); rewrite(fo);
readln(fi,n,m);
fillchar(s,sizeof(s),0);
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:=0 to ct do
begin
for j:=1 to n do
write(fo,s[i,j]:3);
writeln(fo);
end; }
for i:=1 to m do
begin
readln(fi,a,b);
vl:=a;
while b>0 do
begin
st:=1;
ct:=0;
while st<=b do
begin
st:=st shl 1;
inc(ct);
end;
dec(ct);
st:=st shr 1;
b:=b-st;
vl:=s[ct,vl];
end;
writeln(fo,vl);
end;
close(fo);
end.