#include <bits/stdc++.h>
using namespace std;
const int MAXN = 5e5+5;


int n, q;
int a[MAXN];
array<int,31> p[MAXN];

void solve(){
    cin >> n >> q;
    for(int i = 1; i <= n; ++i){
        cin >> a[i];
        a[i] = 31-__builtin_clz(a[i]);
        p[i] = p[i-1];
        p[i][a[i]]++;
    }
    while(q--){
        int l, r;
        cin >> l >> r;
        int ans = 0;
        for(int i = 0; i <= 30; ++i){
            ans = max(ans, p[r][i]-p[l-1][i]);
        }
        cout << ans << '\n';
    }
}



int32_t main(){
    ios_base::sync_with_stdio(0);cin.tie(0);
    int qqq=1;
    //cin >> qqq;
    while(qqq--)solve();
    return 0;
}