/*--------Hakerisanje bf--------*/

#include <iostream>
#include <vector>

using namespace std;

int main(){
    int n, q;
    cin >> n >> q;
    vector<int> pniz(n);
    vector<int> res(q);
    int a, b;
    for(int i = 0; i < n; ++i){
        cin >> pniz[i];
    }
    for(int i = 0; i < q; ++i){
        cin >> a >> b;
        res[i] = pniz[a-1];
        for(int j = a; j < b; ++j){
            res[i] &= pniz[j];
            if(res[i] == 0){
                break;
            }
        }
    }
    for(int i = 0; i < q; ++i){
        cout << res[i] << endl;
    }
    return 0;
}