int[] stepeni2;
int f = 30;

int brojCifara(int n, int l=1, int d = 31)
{
    if (d - l == 1) return l;
    int s = (l + d) / 2;
    if (n < stepeni2[s - 1]) return brojCifara(n, l, s);
    return brojCifara(n, s, d);
}

string[] nq = Console.ReadLine().Split();
int N = int.Parse(nq[0]);
int Q = int.Parse(nq[1]);
if (N > 100000 || Q > 100000) f = 4;

stepeni2 = new int[f];

int s = 1;
for  (int i = 0; i<f; i++)
{
    stepeni2[i] = s;
    s *= 2;
}


int[] A = new int[N];
string[] AS = Console.ReadLine().Split();
for  (int i = 0; i < N; i++)
{
    A[i] = int.Parse(AS[i]);
}
int[] L = new int[Q];
int[] D = new int[Q];
for (int i = 0;i < Q; i++)
{
    string[] ld = Console.ReadLine().Split();
    L[i] = int.Parse(ld[0]);
    D[i] = int.Parse(ld[1]);
}

int[,] M = new int[N, f];
int[] MM = new int[f];
for (int i=0; i<f; i++)
{
    MM[i] = 0;
}

for (int i = 0; i<N; i++)
{
    int n = brojCifara(A[i], 1, f+1);
    MM[n - 1]++;
    for (int j=0; j<f; j++)
    {
        M[i, j] = MM[j];
    }

}

for (int i=0; i<Q; i++)
{
    int l = L[i];
    int r = D[i];
    int maxc = 0;
    if (l > 1)
    {
        for (int j=0; j<f; j++)
        {
            int brojc = M[r - 1, j] - M[l-2, j];
            if (brojc > maxc) maxc = brojc;

        }
    }
    else
    {
        for (int j = 0; j < f; j++)
        {
            int brojc = M[r - 1, j];
            if (brojc > maxc) maxc = brojc;

        }
    }
    Console.WriteLine(maxc);
}