#include <bits/stdc++.h>

using namespace std;
const int N = 2e5 + 5;
int nule[N], a[N];
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    for (int i = 1; i<=n; i++) {
        int x;
        cin >> x;
        a[i] = x;
        nule[i] = nule[i-1];
        if (x == 0)
            nule[i]++;
    }
    if (n <= 1000 && q <= 1000) {
        while (q--) {
        int l, r;
        cin >> l >> r;
        int sol = a[l];
        for (int i = l+1; i<=r; i++)
            sol &= a[i];
        cout << sol << "\n";
        }
    }
    else {
    while (q--) {
        int l, r;
        cin >> l >> r;
        int sol = nule[r] - nule[l-1];
        if (nule > 0) {
            cout << 0 << endl;
        }
        else
            cout << 1 << endl;
    }
    }
    return 0;
}