#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll findHighestSetBit_GCC(unsigned int n) {
   
    
    return 31 - __builtin_clz(n);
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,q; cin >> n >> q;
    vector<ll> a(n);
    vector<vector<ll>>pronadji(31,vector<ll>(n,1));
    for(int i = 0;i<n;i++){
        cin >>a[i];
        ll kljuc = findHighestSetBit_GCC(a[i]);
        for (int b = 0; b < 31; b++) {
            if(i!=0){
                pronadji[b][i] = pronadji[b][i-1];
            }
            
        }
        
        pronadji[kljuc][i]++;
    }
    for(int i=0;i<q;i++){
        ll l,r; cin>> l >> r;
        l--;r--;
        ll maxi=0;
        for(int i = 0; i < 31;i++){
            
            ll brojac=pronadji[i][r]-pronadji[i][l];
            maxi=max(maxi,brojac);
            
            
        }
           
        
       cout<<maxi << '\n';
        
    
    }
    
    

    return 0;
}