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

const ll N=5e5+555;
ll p[N][37],n,q;

ll msb(ll x){
    for(ll i=33;i>=0;--i)
        if(x&(1ll<<i))return i;
    return 0;
}

signed main(){
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin>>n>>q;
    for(int i=1;i<=n;++i){
        ll x;cin>>x;
        x=msb(x);
        for(int j=0;j<35;++j){
            p[i][j]=p[i-1][j];
        }
        ++p[i][x];
    }

    while(q--){
        ll l,r;
        cin>>l>>r;
        ll ans=1;
        for(int i=0;i<35;++i){
            ans=max(ans,p[r][i]-p[l-1][i]);
        }
        cout<<ans<<'\n';
    }
}