#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, q;
    cin >> n >> q;
    vector<long long> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    for (int i = 0; i < n; ++i) {
        int x = floor(log2(a[i]));
        a[i] = x;
    }
    vector<vector<int>> pref(30, vector<int>(n, 0));
    pref[a[0]][0] = 1;
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < 30; ++j) {
            pref[j][i] = pref[j][i - 1] + (a[i] == j);
        }

    }
    while (q--) {
        int l, r;
        cin >> l >> r;
        --l, --r;
        int ans = 0;
        for (int i = 0; i < 30; ++i) {
            ans = max(ans, pref[i][r] - (l > 0 ? pref[i][l - 1] : 0));
        }
        cout << ans << '\n';
    }

    return 0;
}