using System;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        string[] ss = Console.ReadLine().Split();
        int n = int.Parse(ss[0]);
        int q = int.Parse(ss[1]);

        int[] a = new int[n];
        ss = Console.ReadLine().Split();
        for (int i = 0; i < n; i++)
            a[i] = int.Parse(ss[i]);

        int[] l = new int[q];
        int[] r = new int[q];
        for (int i = 0; i < q; i++)
        {
            ss = Console.ReadLine().Split();
            l[i] = int.Parse(ss[0]) - 1; 
            r[i] = int.Parse(ss[1]) - 1;
        }

        for (int j = 0; j < q; j++)
        {
            int L = l[j];
            int R = r[j];

            int max = 1;

            for (int i = L; i <= R; i++)
            {
                bool[] visited = new bool[n];
                max = Math.Max(max, DFS(i, L, R, a, visited));
            }

            Console.WriteLine(max);
        }
    }

    static int DFS(int node, int L, int R, int[] a, bool[] visited)
    {
        visited[node] = true;
        int max = 1;

        for (int i = L; i <= R; i++)
        {
            if (!visited[i] && (a[node] & a[i]) > (a[node] ^ a[i]))
            {
                max = Math.Max(max, 1 + DFS(i, L, R, a, visited));
            }
        }

        visited[node] = false; 
        return max;
    }
}