#include <bits/stdc++.h>
using namespace std;
long long N, Q, n[500005], L, R, Stepen;
int Stepeni[500005][70], Sol, BrStepena;


int NajveciStepen(long long a){
    Stepen = 1;
    BrStepena = 0;
    while(Stepen <= a){
        Stepen <<= 1;
        BrStepena++;
    }
    Stepen >>= 1;
    BrStepena--;

    return BrStepena;
}

void PrefixSuma(long long i){
    for(int j = 1; j <= 64; j++){
        Stepeni[i][j] += Stepeni[i - 1][j];
    }
}

int main(){
    scanf("%lld%lld", &N, &Q);
    for(int i = 1; i <= N; i++){
        scanf("%lld", &n[i]);
        Stepeni[i][NajveciStepen(n[i])]++;
        PrefixSuma(i);
    }

    while(Q--){
        scanf("%lld%lld", &L, &R);

        Sol = 0;
        for(int i = 1; i <= 64; i++){
            Sol = max(Sol, Stepeni[R][i] - Stepeni[L - 1][i]);
        }

        cout << Sol << endl;
    }



return 0;
}