#include <bits/stdc++.h>

using namespace std;
int n;
int niz[200005];
int poj[200005][30];
int q;
int maks;
int makst;
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> q;
    for(int i=1; i<=n; i++){
        cin >> niz[i];
        int st = 0;
        for(int j=0; j<=25; j++)poj[i][j] = poj[i - 1][j];
        while((1<<st) <= niz[i]){
            if((1<<st) & niz[i])poj[i][st]++;
            st++;
        }
        maks = max(maks, niz[i]);
    }
    while(q--){
        int l,r;
        cin >> l >> r;
        int st = 0;
        int res = 0;
        while((1<<st) <= maks){
            int kolko = poj[r][st] - poj[l - 1][st];
            if(kolko == r-l+1) res += (1<<st);
            st++;
        }
        cout << res << endl;
    }
    return 0;
}