#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];
    }
    //cout << "---\n";
    /*for (int i = 1; i < 20; ++i) {
        cout << i << ' ';
        int k = floor(log2(i));
        int l = (1 << k);
        int r = (1 << (k + 1));
        for (int j = l; j < r; ++j) {
            cout << j << ' ';
        }
        cout << '\n';
    }*/
    for (int i = 0; i < n; ++i) {
        long long x = floor(log2(a[i]));
        a[i] = x;
        //cout << x << ' ';
    }
    vector<vector<long long>> pref(31, vector<long long>(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;
        long long 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;
}