#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;

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

}

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

    ll n, q;
    cin>>n>>q;
    vector<ll> niz(n+1);
    //cout<<"rizz";
    for(int i=1; i<n+1; i++)
    {
        cin>>niz[i];
    }
    vector<vector<ll>> a(n+1);
    a[0].resize(40);
    for(int i=1; i<n+1; i++)
    {
        a[i].resize(40);
        for(int j=0; j<40; j++) a[i][j]=0;
        if(niz[i]==0) continue;
        ll najst=najst2(niz[i]);
        //cout<<i<<" "<<najst<<"\n";
        a[i][najst]=1;
    }
    //cout<<"rizz";
    vector<vector<ll>> pref(n+1);
    for(int i=0; i<n+1; i++)
    {
        pref[i].resize(40);
        for(int j=0; j<40; j++)
        {
            pref[i][j]=0;
        }
    }
    for(int i=1; i<n+1; i++)
    {
        for(int j=0; j<40; 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<40; i++)
        {
            ll vr=pref[r][i]-pref[l-1][i];
            if(vr>maks) maks=vr;
        }
        cout<<maks<<"\n";
    }

}