#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;
    vector<long long> v[n];
    for (long long i = 0; i < 30; i++){
        v[0].push_back(0);
    }
    cin >> l;
    v[0][log2(l)]++;
    for (long long i = 1; i < n; i++){
        cin >> l;
        v[i] = v[i - 1];
        v[i][log2(l)]++;
    }
    for (long long i = 0; i < q; i++){
        cin >> l >> r;
        t = 1;
        if (l != 1){
            for (long long j = 0; j < 30; j++){
                t = max(t, v[r - 1][j] - v[l - 2][j]);
            }
        }
        else {
            for (long long j = 0; j < 30; j++){
                t = max(t, v[r - 1][j]);
            }
        }
        cout << t << "\n";
    }
    return 0;
}