#include <bits/stdc++.h>

using namespace std;

int msb(int x) {
    return x ? 31 - __builtin_clz(x) : -1;
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n, q;
    cin >> n >> q;
    int a[n+1];
    int f[n+1][30];
    for (int i = 1; i <= n; ++i) {
        cin >> a[i];
        a[i] = msb(a[i]);
    }
    fill(f[0], f[0]+30, 0);
    for (int i = 1; i <= n; ++i) {
        for (int j = 0; j < 30; ++j) {
            f[i][j] = f[i-1][j];
        }
        f[i][a[i]]++;
    }
    while (q--) {
        int l, r;
        cin >> l >> r;
        int ans = 0;
        for (int i = 0; i < 30; ++i) {
            ans = max(ans, f[r][i] - f[l-1][i]);
        }
        cout << ans << '\n';
    }
    return 0;
}