#include <iostream>
#include <math.h>
#include <vector>
#include <map>

using namespace std;

// ll???

int main()
{
    int n, q;
    scanf("%d %d", &n, &q);
    int a[n], hb[n], max_hb = -1;
    for (int i=0; i<n; i++) {
        scanf("%d", &a[i]);
        hb[i] = log2(a[i]);
        max_hb = max(max_hb, hb[i]);
    }

    int k[max_hb+1][n+1];
    for (int i=0; i<max_hb+1; i++) k[i][0] = 0;
    for (int i=0; i<n; i++) {
        for (int j=0; j<max_hb+1; j++) {
            k[j][i+1] = k[j][i];
        }
        k[hb[i]][i+1] += 1;
    }

    int l, r, res, curr;
    while (q--) {
        scanf("%d %d", &l, &r);
        res = 1;
        for (int i=0; i<max_hb+1; i++) {
            curr = k[i][r] - k[i][l-1];
            res = max(res, curr);
        }
        printf("%d\n", res);
    }

    return 0;
}