#include<iostream>
#include<algorithm>

using namespace std;

int n,q,niz[200005],duzina[200005],najduze[200005][25],bitovi[200005][25],pref[200005],l,r,stepeni[25],maxduz,broj;
bool tr[25];

int main()
{
    stepeni[0]=1;
    cin>>n>>q;
    for(int i=1;i<=n;i++)
    {
        cin>>niz[i];
    }
    pref[1]=niz[1];
    for(int i=2;i<=n;i++)
    {
        pref[i]=pref[i-1]&niz[i];
    }
    while(q--)
    {
        cin>>l>>r;
        broj=niz[l];
        for(int i=l+1;i<=r;i++)
        {
            broj&=niz[i];
        }
        cout<<broj<<endl;
    }

    return 0;
}