#include <iostream>
using namespace std;

const int maks = 500005;
int a[maks];
int g[maks];
int p[31][maks];
int main() 
{
    int n, q;
    cin >> n >> q;
    for (int i = 1; i <= n; i++) 
    {
        cin >> a[i];
        int x = a[i];
        int s = 1;
        int id = 0;
        while (s * 2 <= x) 
        {
            s = s * 2;
            id++;
        }
        g[i] = id;
    }
    for (int i = 0; i <= 30; i++) 
    {
        p[i][0] = 0;
    }
    for (int i = 1; i <= n; i++) 
    {
        for (int j = 0; j <= 30; j++) 
        {
            p[j][i] = p[j][i - 1];
        }
        p[g[i]][i]++;
    }
    while (q--) 
    {
        int l, r;
        cin >> l >> r;
        int mx = 0;
        for (int i = 0; i <= 30; i++) {
            int br = p[i][r] - p[i][l - 1];
            if (br > mx)
                mx = br;
        }
        cout << mx << endl;
    }
    return 0;
}