#include <bits/stdc++.h>

#define pb push_back

using namespace std;

typedef long long ll;

const int N = 2e5 + 5;
int a[N], nula[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++) {
        cin >> a[i];
        nula[i] = nula[i-1];
        if (!a[i]) {
            nula[i]++;
        }
    }

    while (q--) {
        int l, r;
        cin >> l >> r;
        int pref = nula[r] - nula[l-1];
        if (pref > 0) {
            cout << 1 << endl;
        }
        else {
            cout << 0 << endl;
        }
    }
    return 0;
}