string s = Console.ReadLine();
string[] r = s.Split(' ');
int n = int.Parse(r[0]);
int q = int.Parse(r[1]);
s = Console.ReadLine();
r = s.Split(' ');
int[] a = new int[n + 1];
for (int i = 1; i < n + 1; i++)
{
    a[i] = int.Parse(r[i - 1]);
}
int[] rezultatiupita = new int[q];
int p = 0;
for (int i = 0; i < q; i++)
{
    s = Console.ReadLine();
    r = s.Split(' ');
    int levi = int.Parse(r[0]);
    int desni = int.Parse(r[1]);
    rezultatiupita[p++] = najduzipodniz(a, levi, desni);
}
static string binarnizapis(int x)
{
    
    int stepen = 1;
    int z = 0;
    while (stepen <= x) { stepen = stepen * 2; z++; }
    stepen = stepen / 2;
    int[] a = new int[z];
    int i = 0;
    int suma = 0;
    int y = x;
    while (suma != x)
    {
        if (stepen <= y)
        {
            suma += stepen;
            y = y - stepen;
            a[i] = 1;
        }
        stepen = stepen / 2;
        //a[i] = 0;
        i++;
    }
    string s = "";
    for (int j = 0; j < z; j++) s += a[j];
    return s;
    
}
static int najduzipodniz(int[] a, int levi, int desni)
{
    int max = 0;
    for (int i = levi; i <= desni; i++)
    {
        if (a[i] > max) max = a[i];
    }
    int[] brcifaraubinarnom = new int[binarnizapis(max).Length + 1];
    for (int i = levi; i <= desni; i++)
    {
        brcifaraubinarnom[binarnizapis(a[i]).Length]++;
    }
    int max2 = 0;
    for (int i = 0; i < binarnizapis(max).Length + 1; i++)
    {
        if (brcifaraubinarnom[i] > max2) max2 = brcifaraubinarnom[i];
        
    }
    return max2;
}
for (int i = 0; i < q; i++) Console.WriteLine(rezultatiupita[i]);