#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int stepen(int x){
int ans=0;
if(x==0)return 0;
while(x>0){x=x/2;ans++;}
return ans;
}
int main()
{

    int n,q;
    cin>>n>>q;
    vector<int> nums(n);
    for(int i=0;i<n;i++){cin>>nums[i];nums[i]=stepen(nums[i]);}
    vector<int> stepeni_do_cur(31);
    for(int i=0;i<31;i++)stepeni_do_cur[i]=0;
    vector<vector<int>> stepeni_do(n+1);
    stepeni_do[0]=stepeni_do_cur;
    for(int i=1;i<=n;i++){
        stepeni_do_cur[nums[i-1]]++;
        stepeni_do[i]=stepeni_do_cur;
    }
    for(int iq=0;iq<q;iq++){
        int l,r;
        cin>>l>>r;
        l--;r--;
        int ansmax=0;
        for(int i=0;i<31;i++){
            ansmax=max(ansmax,stepeni_do[r+1][i]-stepeni_do[l][i]);
        }
        cout << ansmax << endl;
    }

    return 0;
}