#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll findHighestSetBit_GCC(unsigned int n) {
    if (n == 0) {
        return -1; 
    }
    
    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;
        ll maxi=0;
        for(int i = 0; i < 30;i++){
            ll brojac=0;
            ll kljuc=findHighestSetBit_GCC(i);
            auto it1 = lower_bound(pronadji[kljuc].begin(), pronadji[kljuc].end(), r);
            auto it2 = lower_bound(pronadji[kljuc].begin(), pronadji[kljuc].end(), l);
            brojac=it1-pronadji[kljuc].begin();
            brojac-=(it2-pronadji[kljuc].begin());
            if(brojac>maxi){
                maxi=brojac;
            }
            
            
        }
           
        
        cout<<maxi << '\n';
        
    
    }
    
    

    return 0;
}