#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int nadji_msb(int n) {
    if(n==0) return-1;
    int p=0;
    while(n>>=1)p++;
    return p;}
int prefiks[30][500005];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,q;
    cin>>n>>q;
    for (int i=1;i<=n;i++) {
        int a;
        cin>>a;
        int msb=nadji_msb(a);
        for (int k=0;k<30;k++) {
            prefiks[k][i]=prefiks[k][i-1];}
        if (msb!=-1){
            prefiks[msb][i]++;}}
    while(q--){
        int l,r;
        cin>>l>>r;
        int max_duzina=0;
        for(int k=0;k<30;k++){
            max_duzina=max(max_duzina,prefiks[k][r]-prefiks[k][l-1]);}
        cout<<max_duzina<<"\n";}
    return 0;
}