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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    long long n, q, l, r, t;
    cin >> n >> q;
    long long a[n], x[n];
    for (long long i = 0; i < n; i++){
        cin >> a[i];
        x[i] = log2(a[i]);
    }
    for (long long i = 0; i < q; i++){
        cin >> l >> r;
        t = 0;
        vector<long long> v(30, 0);
        for (long long j = l - 1; j < r; j++){
            v[x[j]]++;
            t = max(t, v[x[j]]);
        }
        cout << t << "\n";
    }
    return 0;
}