#include <bits/stdc++.h>

using namespace std;

unsigned a[200005];
int b[200005][2];
int nule[2000005];
bool nij = true;

void prtbits(unsigned x)
{
    unsigned a;
    for(a = 1<<(sizeof(unsigned)*8-1); a; a>>=1)
    {
        if(a&x) cout << 1;
        else cout << 0;
    }
    cout << endl;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int n, q, l, r, brnula=0;
    bool go = true;
    unsigned g;
    cin >> n >> q;
    for(int i = 1; i<=n; i++)
    {
        cin >> a[i];
        if(a[i]!=0 && a[i]!=1) nij = false;
        if(a[i]==0)
        {
            brnula++;
            nule[brnula] = i;
        }
    }
    for(int i = 1; i<=q; i++)
    {
        cin >> b[i][0] >> b[i][1];
        if(b[i][0] > b[i][1]) swap(b[i][0], b[i][1]);
    }
    if(nij)
    {
        for(int i = 1; i<=q; i++)
        {
            go=true;
            for(int j = 1; j<=brnula; j++)
            {
                if(nule[j]>=b[i][0] && nule[j]<=b[i][1])
                {
                    cout << 0 << endl;
                    go=false;
                    break;
                }
            }
            if(go) cout << 1 << endl;
        }
        return 0;
    }
    for(int i = 1; i<=q; i++)
    {
        g=~(0);
        //prtbits(g);
        //cout << g;
        for(int j = b[i][0]; j<=b[i][1]; j++)
        {
            //cout << (a[j]&(~(0))) << endl;
            g=g&a[j];
        }
        cout << g << endl;
    }
    return 0;
}