/*--------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);
    int a, b;
    for(int i = 0; i < n; ++i){
        cin >> ulaz;
        pniz[i] = ulaz != 0;
    }
    for(int i = 0; i < q; ++i){
        cin >> a >> b;
        res[i] =  true;
        for(int j = a-1; j < b; ++j){
            if(!pniz[j]){
                res[i] = false;
                break;
            }
        }
    }
    for(int i = 0; i < q; ++i){
        cout << res[i] << endl;
    }
    return 0;
}