uses math;
var
t:array[0..600000,0..1,0..1]of longint;
a:array[0..120,0..12001]of longint;
qz,aa:array[0..12001]of longint;
r:array[0..12001]of longint;
b:array[0..34]of longint;
i,ii,j,k,n,m,block,mm,cnt,x,y,ans:longint;
l,ll,rr:int64;
procedure cl(y,yy,z:longint);
var i:longint;
begin
if z=-1 then exit;
i:=x and(1 shl z);
if i>0 then
begin
inc(cnt); t[yy,0]:=t[y,0];
t[yy,1,1]:=cnt; t[yy,1,0]:=t[y,1,0]+1;
cl(t[y,1,1],t[yy,1,1],z-1); exit;
end;
inc(cnt); t[yy,1]:=t[y,1];
t[yy,i,1]:=cnt; t[yy,i,0]:=t[y,i,0]+1;
cl(t[y,i,1],t[yy,i,1],z-1);
end;
function qq(y,yy,z:longint):longint;
var i:longint;
begin
if z=-1 then exit(0);
i:=x and(1 shl z);
if i>0 then
begin
if t[yy,0,0]-t[y,0,0]>0 then
exit(b[z]+qq(t[y,0,1],t[yy,0,1],z-1));
exit(qq(t[y,1,1],t[yy,1,1],z-1));
end;
if t[yy,1,0]-t[y,1,0]>0 then
exit(b[z]+qq(t[y,1,1],t[yy,1,1],z-1));
exit(qq(t[y,0,1],t[yy,0,1],z-1));
end;
begin
b[0]:=1;
for i:=1 to 30 do b[i]:=b[i-1]*2;
readln(n,m);
for i:=1 to n do
begin
read(aa[i]); qz[i]:=aa[i] xor qz[i-1]; x:=qz[i];
inc(cnt); r[i]:=cnt; cl(r[i-1],cnt,30);
end;
block:=trunc(sqrt(n)*1.5)+1;
block:=min(n,block);
i:=1;
while i<=n do
begin
inc(mm);
a[mm,i]:=aa[i];
for j:=i+1 to n do
begin
x:=qz[j]; a[mm,j]:=max(a[mm,j-1],x xor qz[i-1]);
a[mm,j]:=max(a[mm,j],qq(r[i-1],r[j-1],30));
end;
i:=i+block;
end;
for i:=1 to m do
begin
readln(ll,rr);
l:=max((ll+ans)mod n+1,(rr+ans)mod n+1);
ll:=min((ll+ans)mod n+1,(rr+ans)mod n+1);
k:=l; j:=ll; l:=0;
while block*l+1<=j do inc(l);
if block*l+1<=k then
begin
ans:=a[l+1,k]; l:=block*l;
for ii:=j to l do
begin
x:=qz[ii-1];
ans:=max(ans,qq(r[ii-1],r[k],30));
end;
end else
begin
ans:=aa[j];
for ii:=j+1 to k do
begin
x:=qz[ii]; ans:=max(ans,x xor qz[j-1]);
ans:=max(ans,qq(r[j-1],r[ii-1],30));
end;
end;
writeln(ans);
end;
end.