#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 cnt1 = 0;
    int brojevi[n];
    for(int i = 0; i < n; i++){
        cin>>brojevi[i];
        if(brojevi[i] == 1)
            cnt1++;
    }

    bool subtask2 = false;

    for(int i = 0; i < n; i++){
        if(brojevi[i] > 1){
            subtask2 = true;
            break;
            }

    }
    int L, R;

    if(!subtask2){
        //cout<<"ok";
        while(q--){

        int flaga = 0;
        cin>>L>>R;
            if(cnt1 == n){
                cout<<1<<endl;
                continue;
            }
        //int vel = R - L + 1;
        //int hes [vel];
        //int cnt0 = 0;
        for(int i = L ; i < R; i++){
            if(brojevi[i] == 0){
                flaga = 1;
                cout<<"0"<<endl;
                break;
            }
        }

        if(flaga == 0)
            cout<<"1"<<endl;
            //hes
        }
    }
    else
    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

    }

}