#include<bits/stdc++.h>
using namespace std;
int N,Q,r,l,cl=1000;
long long s,niz[200005];
bool imali[1000005];
vector<int> checkpoint,res;
int main() {

    ios_base::sync_with_stdio(false);
    //freopen("hacking.in","r",stdin);
    //freopen("hacking.out","w",stdout);
    cin>>N>>Q;
    for(int i=1;i<=N;i++) {
        cin>>niz[i];
        if((i-1)%cl==0)
            s=niz[i];
        else {
            s&=niz[i];
        }
        if(i%cl==0)
            checkpoint.push_back(s);
    }
  //  return 0;
    for(int j=1;j<=Q;j++) {
        cin>>l>>r;
        if(l<1) l=1;
        if(r>N) r=N;
        s=niz[l];
        for(int i=l+1;i<=r;++i) {
       //     cout<<i<<endl;

           if(i%cl==0 and r>=i+cl) {
               // s&=checkpoint[i/cl];
                i+=cl;
            }
            else {
                if(!imali[niz[i]]) {
                    s=s&niz[i];
                    imali[niz[i]]=true;
                }
            }
            if(s==0)
                res.push_back(s);
        }
        res.push_back(s);
    }
    return 0;
}