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

    for(int i = n - 1; i > 0; i--){
        if(brojevi[i] == 0){
            drugaNula = i;
        }
    }




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

    }*/
    int L, R;

    if(!subtask2){
        //cout<<"ok";
        for(int j = 0; j < q; q--){
        //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;

        if(L == R){
            //cout<<"ok";
            cout<<brojevi[L-1]<<endl;
            continue;
        }

        else if(L-1 < prvaNula && R - 1 > prvaNula){
            cout<<"0"<<endl;
            continue;
        }

        else if(L-1 < drugaNula && R - 1 > drugaNula){
            cout<<"0"<<endl;
            continue;
        }


        for(int i = L - 1 ; 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

    }

}