#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
int main()
{
    ll n,q;cin>>n>>q;

    vector<ll>a;
    for(int i=0;i<n;i++){
        ll x;cin>>x;
        a.push_back(x);
    }
    while(q--){
        ll l,r;cin>>l>>r;
        l--;

        /*ll trZ=0;
        for(int i=l;i<r-1;i++){
            //cout<<a[i]<<"a[i]"<<endl;
            ll zbir=1;
            ll k=0;ll br=a[i];
            while(br>0){
                k++;
                br>>=1;
            }
            ll mask=(1LL<<k)-1;


            //idemo od a[i] do mask
            ll maskTmp=mask;
            if(a[i]%2==1)maskTmp-=1;
            for(int j=i+1;j<r;j++){

                //cout<<a[j]<<"a[j}]"<<endl;
                //cout<<maskTmp<<"mTP"<<endl;
                if((a[j]>=a[i]&&a[j]<=maskTmp)||a[j]==a[i]){
                    zbir++;
                }

            }

            if(zbir>trZ){
                trZ=zbir;
            }

        }

        cout<<trZ<<endl;*/
        ll zbir=1;ll trZbir=0;
        for(int i=l;i<r+1;i++){
            zbir=1;
            for(int j=i+1;j<r;j++){

                if((a[i]&a[j])>(a[i]^a[j])){
                    zbir++;
                }

            }

            if(zbir>trZbir){
                trZbir=zbir;
            }

        }

        cout<<trZbir<<endl;

    }

    return 0;
}