#include <bits/stdc++.h>

using namespace std;

const int MAXN = 500005;
const int BITS = 31;

int dp[BITS][MAXN];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int n, q;
    if (!(cin >> n >> q)) return 0;

    for (int i = 1; i <= n; i++) {
        int x;
        cin >> x;
        
        int msb = 0;
        if (x > 0) msb = 31 - __builtin_clz(x);

        for (int j = 0; j < BITS; j++) {
            dp[j][i] = dp[j][i - 1];
        }
        dp[msb][i]++;
    }

    while (q--) {
        int l, r;
        cin >> l >> r;
        
        int ans = 0;
        for (int j = 0; j < BITS; j++) {
            int cnt = dp[j][r] - dp[j][l - 1];
            if (cnt > ans) ans = cnt;
        }
        cout << ans << "\n";
    }

    return 0;
}