#include <iostream>
#include <vector>
#include <unordered_map>
using namespace std;
int main()
{
    int n,q;
    cin>>n>>q;
    vector<int> a(n+1);
    vector<unordered_map<int,int>> v(n+1);
    for(int i = 1;i<=n;i++)
    {
        cin>>a[i];
        int m = a[i];
        int br = 1;
        while(m/2>0)
        {
            br++;
            m/=2;
        }
        v[i][br]=1;
        /*for(int j = 1;j<=31;j++)
        {
             v[i][j] += v[i-1][j];
             cout<<v[i][j]<<" ";
        }
        cout<<endl;*/
    }

    while(q--)
    {
        int l,r;
        cin>>l>>r;
        int max = 0;
        for(int j = 1;j<=31;j++)
        {
            if(max<v[r][j] - v[l-1][j])
                max = v[r][j] - v[l-1][j];
        }
        cout<<max<<endl;
    }
}