#include <iostream>

using namespace std;
int N, Q;
int main()
{
    cin >> N >> Q;
    int niz[N+1];
    int res[N+1];
    int k[Q];
    for(int i = 0; i < N; i++){
       cin >> niz[i];
       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;
}