#include <bits/stdc++.h>

using namespace std;
int N,Q;
vector<int> resenja;
int niz[200007];
void racunaj(){
    int gap = 0;
    for(int i = 1; i <= N-1; i++){
        for(int j = 1; j <= N-i; j++){
            resenja.push_back(resenja[N*(i-1)+j-gap] & resenja[N*(i-1) - gap + j - 1]);
        }
        gap = i*(i+1)/2;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin >> N >> Q;

    int a;
    for(int i = 1; i <= N; i++){
        cin >> a;
        resenja.push_back(a);
    }
    racunaj();
    int L,R;
    int gap;
    for(int i = 0; i < Q; i++){
        cin >> L >> R;
        gap = (R - L)*(R-L + 1)/2;
        niz[i] = resenja[(R-L)*N+R-gap-1];
    }
    for(int i = 0; i < Q; i++){
        cout << niz[i] << endl;
    }
    return 0;
}