#include <bits/stdc++.h>

using namespace std;

int main()
{
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        int el;
        cin >> el;
        int x = log2(el);
        a[i] = x;
    }

    vector<int> mark(30, -1);
    int la = 0;
    for (int i = 0; i < n; ++i) {
        if (mark[a[i]] == -1) {
            mark[a[i]] = la;
            a[i] = la;
            ++la;
        }
        else {
            a[i] = mark[a[i]];
        }
    }

    int g = *max_element(a.begin(), a.end()) + 1;
    vector<vector<int>> pref(g, vector<int>(n, 0));
    pref[a[0]][0] = 1;
    for (int i = 1; i < n; ++i) {
        for (int j = 0; j < g; ++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 < g; ++i) {
            ans = max(ans, pref[i][r] - (l > 0 ? pref[i][l - 1] : 0));
        }
        cout << ans << '\n';
    }

    return 0;
}