#include <bits/stdc++.h>
using namespace std;

vector <int> s;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
int n,q;

cin >>n>>q;
vector <int> a(n);
for(int i=0;i<n;i++){
    cin >>a[i];
}

int current=a[0];
int added=0;
int sq=sqrt(n);

for(int i=0;i<n;i++){
if(added==(int)sq){
    added=0;
    s.push_back(current);
    if(i+1>=n){
        break;
    }
    current=a[i+1];
}
else{
    added++;
    current&=a[i];

}
}

s.push_back(current);


for(int i=0;i<q;i++){
int l,r;
cin >>l>>r;
r--;
l--;
int rez=a[l];
while((r+1)%(int)sq!=0){
rez&=a[r];
r--;
}
while((l)%(int)sq!=0){
rez&=a[l];
l++;
}
 added=0;
int x=l;
while(added!=(r-l+1)){
    rez&=s[x];
    x++;
    added+=sq;
}
cout <<rez<<endl;
}

}