#include <bits/stdc++.h>

#define ll long long
#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pb push_back
#define mod 1000000007

using namespace std;

int n,q,a[200100],d[200100][25];
vector<int>v;

void turn(int x){
    v.clear();
    while(x>0){
        v.pb(x%2);
        x/=2;
    }
    while(v.size()<23)v.pb(0);
    reverse(all(v));
}
/*
5 4
1 5 4 3 2
1 3
4 5
2 5
2 3
*/
int main(){
    ios;
    memset(d,0,sizeof(d));
    cin>>n>>q;
    for (int i=1;i<=n;i++){
        cin>>a[i];
        for (int j=0;j<=23;j++){
            d[i][j]=d[i-1][j];
        }
        turn(a[i]);
        for (int j=0;j<v.size();j++){
            d[i][j]=d[i][j]+v[j];
        }
    }
    while(q--){
        int l,r;
        cin>>l>>r;
        int dif=r-l+1,ans=0,st=0;
        for (int j=v.size()-1;j>=0;j--){
            if (d[r][j]-d[l-1][j]==dif)ans+=pow(2,st);
            st++;
        }
        cout<<ans<<"\n";
    }
    return 0;
}