using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

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

        static void Main()
        {
            string[] s= Console.ReadLine().Split();
            int n = int.Parse(s[0]);
            int upit= int.Parse(s[1]);

            string[] s2 = Console.ReadLine().Split();

            int[] niz = new int[n];
            int[] Resenja = new int[upit];

            for (int i=0; i<s2.Length; i++)
            {
                niz[i] = int.Parse(s2[i]);

            }

            int red = 30; 
            int[,] prefiksiMatrica = new int[red, n + 1];
   
            for (int i = 1; i <= n; i++)
            {

                for (int b = 0; b < red; b++)
                {
                    prefiksiMatrica[b, i] = prefiksiMatrica[b, i - 1];
                }
                int m = IneksPrekida(niz[i - 1]);
                prefiksiMatrica[m, i]++;
            }

            for (int j = 0; j <upit; j++)
            {
                var lr = Console.ReadLine().Split();
                int leva = int.Parse(lr[0]);
                int desna = int.Parse(lr[1]);

                int najb = 0;
                for (int b = 0; b < red; b++)
                {
                    int tre = prefiksiMatrica[b, desna] - prefiksiMatrica[b, leva - 1];
                    if (tre > najb)
                    {
                        najb = prefiksiMatrica[b, desna] - prefiksiMatrica[b, leva - 1];
                    }
                }

                Resenja[j] = najb;
            }

            foreach (int x in Resenja)
            {
                Console.WriteLine(x);
            }
        }
    }
}