#include <iostream>
#include <vector>
#include<algorithm>;
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<long long>opsezi;
    opsezi.push_back(1);
    long long op = 2;
    for (int i = 1; i < 31; i++) {
        opsezi.push_back(op);
        op *= 2;
    }
    /*for (int i = 0; i < n + 1; i++) {
        cout << opsezi[i] << " ";
    }*/
    vector<vector<int>>bro(n + 1, vector<int>(31, 0));
    vector<long long>v(n);
    for (int i = 0; i < n; i++) {
        cin >> v[i];
        auto it = upper_bound(opsezi.begin(), opsezi.end(), v[i]);
        
        int ind = it - opsezi.begin();
        //cout << v[i] << " " << ind;
        bro[i + 1][ind] += 1;
        for (int j = 0; j < 31; j++) {
            bro[i + 1][j] += bro[i][j];
        }

    }

    while (q--) {
        cin >> l >> r;
        int maxx = 0;
        for (int j = 0; j < 31; j++) {
            maxx = max(maxx, bro[r][j] - bro[l - 1][j]);
        }
        cout << maxx << "\n";
    }
}