#include <bits/stdc++.h>
using namespace std;

int n, q;
vector<int> a;

bool input() {
    cin >> n >> q;
    a = vector<int>(n, 0);
    bool only_bin = true;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (a[i] != 0 || a[i] != 1)
            only_bin = false;
    }

    return only_bin;
}

void brute_force() {
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        int val = a[l - 1];

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

        /// OUTPUT

        cout << val << '\n';
    }
}

void smart_bin() {
    for (int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;
        bool found_zero = false;

        for (int i = l; i <= r; i++) {
            if (a[i] == 0) {
                found_zero = true;
                break;
            }
        }

        if (found_zero)
            cout << "0\n";
        else
            cout << "1\n";
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    if (input())
        smart_bin();
    else
        brute_force();

    return 0;
}