#include <bits/stdc++.h>

using namespace std;
const int NAJ = 1e4 +9;
int N,Q;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0),cout.tie(0);
    cin >> N >> Q;
    int resa[1][N];
    bool suma = true;


    for(int i = 1; i <= N; i++){
        cin >> resa[1][i];
        if(resa[1][i] != 1 || resa[1][i] != 0)
            suma = false;
    }


    if(suma){
        int niz[N+1];
        int res[N+1];
        int k[Q];
        for(int i = 0; i < N; i++){
            niz[i] = resa[1][i+1];
            res[i] = 0;
        }
        for(int i = 1; i < N; i++){
            res[i] = niz[i-1] & niz[i];
        }
        for(int i = 2; i < N; i++){
            res[i] += res[i-1];
        }
        int L,R;
        for(int i = 0; i < Q; i++){
            cin >> L >> R;
            if(res[R-1] - res[L-1] == R-L && niz[R-1] != 0)
                k[i] = 1;
            else
                k[i] = 0;
        }
        for(int i = 0; i < Q; i++){
            cout << k[i] << " ";
        }
        return 0;
    }
    else{
        int resenja[N][N];
        int niz[Q+1];
        for(int i = 1; i <= N; i++){
            resenja[1][i] = resa[1][i];
        }
        for(int i = 2; i <= N; i++){
            for(int j = i; j <= N; j++){
                resenja[i][j] = resenja[i-1][j] & resenja[i-1][j-1];
            }
        }
        int L,R;
        for(int i = 0; i < Q; i++){
            cin >> L >> R;
            niz[i] = resenja[R-L+1][R];
        }
        for(int i = 0; i < Q; i++){
            cout << niz[i] << endl;
        }
        return 0;
    }
}