#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    int a[n];
    set<int> s;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
        s.insert(a[i]);
    }


    if(n <= 10000)
    {
        while(q--)
        {
            int l, r;
            cin >> l >> r;
            int br = a[l-1];
            for(int i = l; i < r; i++)
                br &= a[i];

            cout << br << "\n";
        }
    }

    else if(s.size() < 3)
    {
        int br1[n], br0[n];
        br1[0] = br0[0] = 0;

        for(int i = 0; i < n; i++)
        {
            br1[i] += (a[i] == 1);
            br0[i] += (a[i] == 0);
        }

        while(q--)
        {
            int l, r;
            cin >> l >> r;
            int x;
            if(l == 1)
                x = br0[r-1];
            else
                x = br0[r-1]-br0[l-2];
            if(x > 0)
                cout << 0 << "\n";
            else
                cout << 1 << "\n";
        }

    }

}