#include <iostream>
#include<vector>
#include<algorithm>
using namespace std;
vector<int> A;
int stepeni(int N)
{
    int max = 0;
    for (int i = 0; i < N; i++)
    {
        int k = 0, e = 1;
        while (e <= A[i])
        {
            if (e * e <= A[i]) { k *= 2; e *= e; }
            e *= 2;
            k++;
        }
        A[i] = k;
        if (k > max)max = k;
    }
    return max;
}
int main()
{
    int N, Q;
    cin >> N;
    cin >> Q;
    A.resize(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    int max = stepeni(N);
    vector<int> pocetak1(Q);
    vector<int> kraj1(Q);
    for (int i = 0; i < Q; i++)
    {
       cin>> pocetak1[i];
       cin >> kraj1[i];
    }
    vector<int> B;
    for (int i = 0; i < Q; i++)
    {
        int max2 = 0;
        int pocetak = pocetak1[i]-1;
        int kraj = kraj1[i]-1;
        B.clear();
        B.resize(max + 1);
        
        for (int j = pocetak; j <= kraj; j++)B[A[j]]++;

        for (int t = 0; t < max + 1; t++)if (B[t] > max2)max2 = B[t];
        cout << max2 << "\n";
    }
    return 0;

}