#include<bits/stdc++.h>
using namespace std;
int duzina(int n){
	int d = 1;
	while(n>=2){
		n/=2;
		d++;
	}
	return d;
}
int main(){
	int maks = 31;
	int n;
	cin>>n;
	int q;
	cin>>q;
	int a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
		a[i] = duzina(a[i]);
	}
	int pref[n+1][31];
	for(int i=0;i<31;i++) pref[0][i] = 0; 
	for(int i=1;i<n+1;i++){
		for(int j=0;j<31;j++){
			if(a[i-1] == j+1) pref[i][j] = pref[i-1][j]+1;
			else pref[i][j] = pref[i-1][j];
		}
	}
	while(q--){
		int l,r;
		cin>>l>>r;
		l--;
		r--;
		int res = 0;
		for(int i=0;i<31;i++){
			int tr = pref[r+1][i]-pref[l][i];
			res = max(res, tr);
		}
		cout<<res<<endl;
	}
}