#include <bits/stdc++.h>
#define ll long long

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    ll q,n;
    cin >> n >> q;
    ll niz[n];
    ll l,r;
    ll vr[n];
    ll resenje[q];
    cin >> niz[0];
    for(ll i=1;i<n;i++)
    {
        cin >> niz[i];
        vr[i-1]=niz[i]&niz[i-1];
    }
    /*for(ll i=0;i<n-1;i++)
    {
        cout << vr[i] << endl;
    }
    cout << " --- " << endl;*/
    for(int i=0;i<q;i++)
    {
        cin >> l >> r;
        l--;
        r--;
        if(abs(l-r)<=1)
        {
            //cout << "jedan pored drugog, resenje: " << vr[l] << endl;
            resenje[i] = vr[l];
        }
        else
        {
            //cout << "nisu jedan pored drugog" << endl;
            resenje[i]=INT_MAX;
            for(int j=l;j<=r;j++)
            {
                resenje[i]=resenje[i]&vr[j];
                //cout << ": " << resenje[i] << endl;
                if(resenje[i]==0)break;
            }
        }
    }
    for(ll i=0;i<q;i++)
    {
        cout << resenje[i] << endl;
    }
}