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

#include <iostream>
#include <vector>
#include <utility>

using namespace std;

vector<vector<char> > piramida;

int popuni(int * xy);

int main()
{
    int n, q;
    int maxs = 0;
    cin >> n >> q;
    vector<bool> res(q);
    vector<pair<int, int> > ulaz(q);
    piramida.resize(n);
    piramida[0].resize(n);
    for(int i = 0; i < n; ++i){
        cin >> piramida[0][i];
    }
    for(int i = 0; i < q; ++i){
        cin >> ulaz[i].second >> ulaz[i].first;
        ulaz[i].first -= ulaz[i].second;
        --ulaz[i].second;
        if(ulaz[i].first > maxs){
            maxs = ulaz[i].first;
        }
    }
    maxs = n - maxs - 1;
    for(int i = n-1; i > maxs; --i){
        piramida[n-i].resize(i);
        for(int j = 0; j < i; ++j){
            piramida[n-i][j] = -1;
        }
    }
    int ulaz2[2];
    for(int i = 0; i < q; ++i){
        ulaz2[0] = ulaz[i].first;
        ulaz2[1] = ulaz[i].second;
        res[i] = popuni(ulaz2);
    }
    for(int i = 0; i < q; ++i){
        cout << res[i] << endl;
    }
    return 0;
}

int popuni(int * xy){
    if(piramida[xy[0]][xy[1]] != -1){
        return piramida[xy[0]][xy[1]];
    }
    if(xy[0] == 1){
        piramida[xy[0]][xy[1]] = piramida[xy[0]-1][xy[1]]&&piramida[xy[0]-1][xy[1]+1];
        return piramida[xy[0]][xy[1]];
    }
    if(piramida[xy[0]-1][xy[1]] != -1){
        int * res = new int[2];
        res[0] = xy[0]-2;
        res[1] = xy[1]+2;
        piramida[xy[0]][xy[1]] = popuni(res)&&piramida[xy[0]-1][xy[1]];
        delete res;
    }
    else if(piramida[xy[0]-1][xy[1]+1] != -1){
        int * res = new int[2];
        res[0] = xy[0]-2;
        res[1] = xy[1];
        piramida[xy[0]][xy[1]] = popuni(res)&&piramida[xy[0]-1][xy[1]+1];
        delete res;
    }
    else{
        int * res = new int[4];
        res[0] = xy[0]-1;
        res[1] = xy[1];
        res[2] = xy[0]-2;
        res[3] = xy[1]+2;
        piramida[xy[0]][xy[1]] = popuni(res)&&popuni(res + 2);
        delete res;
    }
    return piramida[xy[0]][xy[1]];
}