/*--------Hakerisanje 2--------*/

#include <iostream>
#include <vector>

using namespace std;

vector<vector<int> > piramida;

int popuni(int a, int b);

int main()
{
    int n, q;
    int a, b;
    int ulaz;
    cin >> n >> q;
    vector<int> res(q);
    piramida.resize(n);
    for(int i = n; i > 0; --i){
        piramida[n-i].resize(i);
        for(int j = 0; j < i; ++j){
            piramida[n-i][j] = -1;
        }
    }
    for(int i = 0; i < n; ++i){
        cin >> piramida[0][i];
    }
    for(int i = 0; i < q; ++i){
        cin >> a >> b;
        res[i] = popuni(b-a, a-1);
    }
    for(int i = 0; i < q; ++i){
        cout << res[i] << endl;
    }
    return 0;
}

int popuni(int a, int b){
    if(piramida[a][b] != -1){
        return piramida[a][b];
    }
    if(a == 1){
        piramida[a][b] = piramida[a-1][b]&piramida[a-1][b+1];
        return piramida[a][b];
    }
    if(piramida[a-1][b] != -1){
        piramida[a][b] = popuni(a-2, b+2)&piramida[a-1][b];
    }
    else if(piramida[a-1][b+1] != -1){
        piramida[a][b] = popuni(a-2, b)&piramida[a-1][b+1];
    }
    else{
        piramida[a][b] = popuni(a-1, b)&popuni(a-2, b+2);
    }
    return piramida[a][b];
}