#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    uint32_t N, Q, L, R;
    bool breakout;

    cin >> N >> Q;

    vector<uint32_t> B;

    uint32_t A[N];
    for(uint32_t i = 0; i < N; i++) cin >> A[i];

    for( ; Q--;){
        cin >> L >> R;
        for(uint32_t x : B){
            if(L - 1 < x && x < R){
                cout << "0\n";
                L = R;
                break;
            }
        }

        breakout = true;

        for(uint32_t i = L - 1; i < R; i++){
            if(!A[i]){
                cout << "0\n";
                breakout = false;
                B.push_back(i);
                break;
            }
        }

        if(breakout) cout << "1\n";
    }
}