#include <bits/stdc++.h>

using namespace std;

int n, q;
int niz[200010];

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

    cin>>n>>q;

    int brNula[200010];
    brNula[0]=0;
    for (int i=1; i<=n; i++)
    {
        cin>>niz[i];
        if (niz[i]==0)
            brNula[i]=brNula[i-1]+1;
        else
            brNula[i]=brNula[i-1];
    }

    long long ress;
    for (int i=0; i<q; i++)
    {
        int l, r;
        cin>>l>>r;
        ress=niz[l];
        if ((long long)(q*n)>1000000000)
        {
            if (brNula[r]-brNula[l-1]>0)
                ress=0;
            else
                ress=1;

            cout<<ress<<endl;
        }
        else
        {
            for (int j=l; j<=r; j++)
                ress&=niz[j];
            cout<<ress<<endl;
        }
    }

}