#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pf push_front
int n,q,lista[300000],brojac[300000][50],sume[300000][50];

/*
5 4
1 5 4 3 2
1 3
4 5
2 5
2 3

0
2
0
4

*/

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n >> q;

    for(int i=1;i<=n;i++){
        cin >> lista[i];
        ll cnt=0;
        while(lista[i]){
            if(lista[i]&1)brojac[i][cnt]++;
            lista[i]/=2;
            cnt++;
        }
    }

    for(int i=1;i<=n;i++){
        for(int j=0;j<=40;j++){
            sume[i][j]=sume[i-1][j]+brojac[i][j];
        }
    }
    while(q--){
        ll l,r;
        cin >> l >> r;
        ll brojeva=r-l+1;
        ll temp=0;
        for(int i=0;i<40;i++){
            if(sume[r][i]-sume[l-1][i]==brojeva)temp+=(1<<i);
        }
        cout << temp << endl;
    }


    return 0;
}