#include <bits/stdc++.h>

using namespace std;

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, q;
    cin>>n>>q;
    int brojevi[n];
    for(int i = 0; i < n; i++){
        cin>>brojevi[i];
    }

    int L, R;
    while(q--){
        cin>>L>>R;
        //int vel = R - L + 1;
        //int hes [vel];
        int res = brojevi[L-1];
        for(int i = L ; i < R; i++){
            res = res & brojevi[i];
        }
        cout<<res<<endl;
            //hes

    }

}