#include <bits/stdc++.h>
using namespace std;

int br[200005][25];

int main(){

    int n, q;
    cin >> n >> q;
    for(int i=1; i<=n; i++){
        for(int j=0; j<=20; j++){
            br[i][j] = br[i-1][j];
        }
        int x;
        cin >> x;
        int cnt = 0;
        while(x){
            if(x%2) br[i][cnt]++;
            x /= 2;
            cnt++;
        }
    }
    while(q--){
        int l, r;
        cin >> l >> r;
        int res = 0;
        for(int j=0; j<=20; j++){
            int x = br[r][j] - br[l-1][j];
            if(x == r-l+1) res += (1 << j);
        }
        cout << res << "\n";
    }
    return 0;
}