#include <bits/stdc++.h>

using namespace std;

 main()
{


    int n, m;



    cin>>n>> m;
    vector<vector<int>> prefiks(30,vector<int>(n+1,0));


    for (int i=1 ;i<=n;i++)
    {

        int a;
        cin>>a;

        int MSB=31-__builtin_clz(a);


        for (int b=0; b<30;b++)
        {
            prefiks[b][i]=prefiks[b][i-1];

        }

        prefiks[MSB][i]++;

    }

    while(m--)

    {
        int l,f;
        cin>>l>> f;

        int aNS= 0;
        for (int b=0;b<30;b++)


            aNS=max(aNS,prefiks[b][f]-prefiks[b][f -1]);
        }
        cout<< aNS<<" \n";
    }



}