#include <bits/stdc++.h>

using namespace std;

void run(int br0[], int q) {

    for(int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;

        if(l > 1 && br0[r - 1] - br0[l - 2] > 0) {
            cout << 0 << endl;
            continue;
        } else {
            if(l == 1 && br0[r - 1] > 0) {
                cout << 0 << endl;
                continue;
            }
        }

        cout << 1 << endl;
    }
}

int main() {

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

    int n, q;
    cin >> n >> q;

    int a[n], br0[n];
    bool z = true;
    br0[0] = 0;
    for(int i = 0; i < n; i++) {
        cin >> a[i];

        if(a[i] == 0)
            br0[i] = (i == 0 ? 0 : br0[i - 1]) + 1;
        else
            br0[i] = (i == 0 ? 0 : br0[i - 1]);
        if(a[i] > 1)
            z = false;
    }

    if(z) {
        run(br0, q);
        return 0;
    }

    for(int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;

        int sol = a[l - 1];
        for(int j = l; j < r; j++) {
            sol = (sol & a[j]);
        }

        cout << sol << endl;
    }

    return 0;
}