/*--------Hakerisanje 2--------*/

#include <iostream>
#include <vector>

using namespace std;

int main()
{
    int n, q;
    int ulaz;
    cin >> n >> q;
    vector<bool> pniz(n);
    vector<bool> res(q, true);
    vector<int> falseI;
    int a, b;
    for(int i = 0; i < n; ++i){
        cin >> ulaz;
        if(ulaz == 0){
            falseI.push_back(i);
        }
    }
    int s = falseI.size();
    for(int i = 0; i < q; ++i){
        cin >> a >> b;
        for(int j = 0; falseI[j] < b; ++j){
            if(falseI[j] >= a-1){
                res[i] = false;
                break;
            }
        }
    }
    for(int i = 0; i < q; ++i){
        cout << res[i] << endl;
    }
    return 0;
}