#include <bits/stdc++.h>

using namespace std;

#define MAXN 500001
#define MAXM 31

int n,q,a[MAXN];
int pref[MAXM][MAXN];

int main()
{
    cin>>n>>q;
    for (int i=1;i<=n;i++) cin>>a[i];
    for (int bit=0;bit<MAXM;bit++) pref[bit][0]=0;
    for (int i=1;i<=n;i++)
    {
        int maxbit=-1;
        for (int bit=0;bit<MAXM;bit++)
        {
            pref[bit][i]=pref[bit][i-1];
            if (a[i]&(1<<bit)) maxbit=bit;
        }
        pref[maxbit][i]++;
    }
    for (int i=1;i<=q;i++)
    {
        int l,r;cin>>l>>r;int currans=0;
        for (int bit=0;bit<MAXM;bit++) currans=max(currans,pref[bit][r]-pref[bit][l-1]);
        cout<<currans<<endl;
    }
}