#include <bits/stdc++.h>
#define pb push_back
#define ll long long int
#define pi pair<int, int>
#define all(x) x.begin(), x.end()




using namespace std;

const int nmax=5*1e5+5;
ll niz[nmax];
ll a[nmax][30];
ll pref[nmax][30];


ll najst2(ll x)
{
    ll p=1, st=0;
    while(p<=x) {p*=2; st++;}
    p/=2;
    st--;
    return st;

}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    ll n, q;
    cin>>n>>q;
    //cout<<"rizz";
    for(int i=1; i<n+1; i++)
    {
        cin>>niz[i];
    }
    for(int i=1; i<n+1; i++)
    {
        if(niz[i]==0) continue;
        ll najst=najst2(niz[i]);
        //cout<<i<<" "<<najst<<"\n";
        a[i][najst]=1;
    }
    //cout<<"rizz";
    for(int i=1; i<n+1; i++)
    {
        for(int j=0; j<30; j++)
        {
            pref[i][j]=pref[i-1][j]+a[i][j];
        }
    }
    while(q--)
    {
        ll l, r;
        cin>>l>>r;
        ll maks=1;
        for(int i=0; i<30; i++)
        {
            ll vr=pref[r][i]-pref[l-1][i];
            if(vr>maks) maks=vr;
        }
        cout<<maks<<"\n";
    }

}