namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            string[] unos = Console.ReadLine().Split();
            int n=Convert.ToInt32(unos[0]);
            int q=Convert.ToInt32(unos[1]);
            string[] brojevi = Console.ReadLine().Split();
            int[]a=new int[n];
            for (int i = 0; i < n; i++)
                a[i] = Convert.ToInt32(brojevi[i]);
            int[]l=new int[q];
            int[]r=new int[q];
            int[] k = new int[q];
            for (int i = 0; i < q; i++)
            {
                string[] lr = Console.ReadLine().Split();
                l[i] = Convert.ToInt32(lr[0]);
                r[i] = Convert.ToInt32(lr[1]);
            }
            for (int i = 0; i < q; i++)
            {
                for (int j = l[i]; j < r[i]; j++)
                {
                    if ((a[l[i]] & a[r[i]]) > (a[l[i]] ^ a[r[i]]))
                        k[i] = r[i];
                }
            }
            foreach (int br in k)
            {
                Console.WriteLine(k);
            }
        }
    }
}