#include<bits/stdc++.h>
using namespace std;
int N,Q,r,l;
long long s,niz[200005];
vector<int> checkpoint;
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)%1000==0)
            s=niz[i];
        else {
            s&=niz[i];
        }
        if(i%1000==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++) {
            if(i%1000==0 and r>=i+1000) {
                s&=checkpoint[i/1000];
                i+=1000;
            }
            else
                s&=niz[i];
            if(s==0)
                cout<<"0\n";
        }
        cout<<s<<"\n";
    }
    return 0;
}