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

int a[200010];
pair <int, int> b[200010];
pair <int, int> c[200010];

bool dalije (int n) {
    for (int i = 1; i <= n; i++) {
        if (a[i] != 1 && a[i] != 0)
            return false;
    }
    return true;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q;
    cin >> n;
    cin >> q;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 0; i < q; i++) {
        cin >> b[i].first;
        cin >> b[i].second;
    }
    if (dalije(n)) {
        if (a[1] == 1)
            c[1].first++;
        else
            c[1].second++;
        for (int i = 2; i <= n; i++) {
            c[i].first = c[i - 1].first;
            c[i].second = c[i - 1].second;
            if (a[i] == 1)
                c[i].first++;
            else
                c[i].second++;
        }
        int x = 0, y = 1;
        for (int i = 0; i < q; i++) {
            if (c[b[i].second].second - c[b[i].first - 1].second > 0)
                cout << x << endl;
            else
                cout << y << endl;
        }
        return 0;
    }
    for (int i = 0; i < q; i++) {
        int x = 0;
        if (b[i].first > b[i].second) {
            cout << x << endl;
            continue;
        }
        int resenje = a[b[i].first];
        for (int j = b[i].first + 1; j <= b[i].second; j++) {
            resenje = resenje & a[j];
        }
        cout << resenje << endl;
    }

    return 0;
}