#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    ll q,n;
    cin >> n >> q;
    ll niz[n];
    ll l,r;
    for(ll i=0;i<n;i++) cin >> niz[i];
    ll resenje[q];
    //cout << "----" << endl;
    for(ll i=0;i<q;i++)
    {
        cin >> l >> r;
        l--;
        r--;
        resenje[i]=INT_MAX;
        for(ll j=l;j<=r;j++)
        {
            resenje[i] = resenje[i]&niz[j];
            if(resenje[i]==0)break;
            //cout << resenje[i] << endl;
        }
        //cout << endl;
    }
    //cout << "----" << endl;
    for(ll i=0;i<q;i++)
    {
        cout << resenje[i] << endl;
    }
}