#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll N = 2e5+34;
const ll lg = 22;

ll a[N],pf[N][lg];

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n,q;
    cin >> n >> q;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        for(int j = 0; j < lg; j++){
            pf[i][j] = pf[i-1][j];
            if((a[i] >> j) & 1){
                pf[i][j]++;
            }
        }
    }
    while(q--){
        ll l,r;
        cin >> l >> r;
        ll sol = 0;
        for(int j = 0; j < lg; j++){
            ll ima = pf[r][j] - pf[l-1][j];
            if(ima == r-l+1){
                sol += (1 << j);
            }
        }
        cout << sol << endl;
    }
}