#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);
    for(int i = 0;i<n;i++){
        cin >>a[i];
        ll kljuc = findHighestSetBit_GCC(a[i]);
        pronadji[kljuc].push_back(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=0;
            auto it1 = upper_bound(pronadji[i].begin(), pronadji[i].end(), r);
            auto it2 = lower_bound(pronadji[i].begin(), pronadji[i].end(), l);
            brojac=(int(it1-it2));
            maxi=max(maxi,brojac);
            
            
        }
           
        
       cout<<maxi << '\n';
        
    
    }
    
    

    return 0;
}