#include <bits/stdc++.h>
using namespace std;

int funk(int x) {
    int a = 0;
    while (x > 1) {
        x >>= 1;
        a++;
    }
    return a;
}

int main() {

    int N, Q;
    cin >> N >> Q;

    vector<int> A(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }

    const int lim = 31;
    vector<vector<int>> pref(lim, vector<int>(N + 1, 0));

    // build prefix sums
    for (int i = 1; i <= N; i++) {
        int b = funk(A[i]);
        for (int j = 0; j < lim; j++) {
            pref[j][i] = pref[j][i - 1];
        }
        pref[b][i]++;
    }

    // read all queries first
    vector<pair<int,int>> q(Q);
    for (int i = 0; i < Q; i++) {
        cin >> q[i].first >> q[i].second;
    }

    // process and store answers
    vector<int> maxx(Q);
    for (int i = 0; i < Q; i++) {
        int L = q[i].first;
        int R = q[i].second;

        int br = 0;
        for (int j = 0; j < lim; j++) {
            br = max(br, pref[j][R] - pref[j][L - 1]);
        }
        maxx[i] = br;
    }

    // output strictly after input
    for (int x : maxx) {
        cout << x << '\n';
    }

    return 0;
}