#include <iostream>
#include <vector>
#include<cmath>;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);

    int n, q,l,r;
    cin >> n >> q;
    vector<int>opsezi(n + 1);
    opsezi[0] = opsezi[1] = 1;
    int op = 2;
    for (int i = 2; i < n+1; i++) {
        int step = pow(2, op) - 1;
        if (i < step) opsezi[i] = op;
        if (i == step) {
            opsezi[i] = op; op += 1;
        }
    }
    /*for (int i = 0; i < n + 1; i++) {
        cout << opsezi[i] << " ";
    }*/
    vector<vector<int>>bro(n + 1, vector<int>(25,0));
    vector<int>v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        bro[i + 1][opsezi[v[i]]] += 1;
        for (int j = 0; j < 25; j++) {
            bro[i + 1][j] += bro[i][j];
        }
        
    }
    
    while (q--) {
        cin >> l >> r;
        int maxx = 0;
        for (int j = 0; j < 25; j++) {
            maxx = max(maxx, bro[r][j] - bro[l - 1][j]);
        }
        cout << maxx << "\n";
    }
}