using System;
using System.IO;
using System.Text;

class Program
{
    static int fja(int x)
    {
        int b = 0;
        while ((1 << (b + 1)) <= x) 
            b++;
        return b;
    }

    static void Main()
    {
        string[] unos = Console.ReadLine().Split();
        int N = Convert.ToInt32(unos[0]);
        int Q = Convert.ToInt32(unos[1]);

        int[] A = new int[N + 1];
        unos = Console.ReadLine().Split();
        for (int i = 1; i <= N; i++)
            A[i] = Convert.ToInt32(unos[i - 1]);

        int[,] matrica = new int[31, N + 1];

        for (int i = 1; i <= N; i++)
        {
            for (int b = 0; b < 31; b++)
                matrica[b, i] = matrica[b, i - 1];

            int deo = fja(A[i]);
            matrica[deo, i]++;
        }

        StringBuilder s = new StringBuilder();

        while (Q-- > 0)
        {
            unos = Console.ReadLine().Split();
            int L = Convert.ToInt32(unos[0]);
            int R = Convert.ToInt32(unos[1]);

            int naj = 0;
            for (int b = 0; b < 31; b++)
            {
                int c = matrica[b, R] - matrica[b, L - 1];
                if (c > naj) 
                    naj = c;
            }

            s.AppendLine(naj.ToString());
        }

        Console.Write(s.ToString());
    }
}