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

namespace ConsoleApp2
{
    internal class Program
    {
        static int funkc(int x)
        {
            int p=0;

            while ((1<<(p + 1))<=x)
            {
                p++; 
            }
            return p;
        }
        static void Main(string[] args)
        {
            var ulaz=Console.ReadLine().Split();

            int n=int.Parse(ulaz[0]);
            int q=int.Parse(ulaz[1]);

            int[] niz=Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

            int[,] p=new int[31,n+1];

            for (int i=0; i<n; i++)
            {
                int b=funkc(niz[i]);

                for (int j=0; j<31; j++)
                {
                    p[j,i+1] = p[j,i];
                }

                p[b,i+1]++;
            }

            StringBuilder sb=new StringBuilder();

            while (q-- > 0)
            {
                var ulaz2=Console.ReadLine().Split();

                int l=int.Parse(ulaz2[0]) - 1;
                int r=int.Parse(ulaz2[1]);

                int max=0;

                for (int i=0; i<31; i++)
                {
                    int c=p[i,r]-p[i,l];

                    if (c>max)
                    {
                        max=c;
                    }
                }

                sb.AppendLine(max.ToString());
            }

            Console.Write(sb.ToString());
            Console.WriteLine();
        }
    }
}