#include <iostream>
#include <bits/stdc++.h>

using namespace std;

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

    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        int b;
        cin >> b;
        for(int j = 1; j < 32; j++){
            if(b < ((long long)1 << j)){
                a[i] = j;
                break;
            }
        }
    }

    vector<vector<int>> pref(n+1, vector<int> (32, 0));

    for(int i = 0; i < n; i++){
        for(int j = 0; j < 32; j++){
            if(a[i] == j) pref[i+1][j] = pref[i][j]+1;
            else pref[i+1][j] = pref[i][j];
        }
    }

    for(int i = 0; i < q; i++){
        int l, r;
        cin >> l >> r;
        int m = 0;
        for(int j = 0; j < 32; j++){
            m = max(m, pref[r][j]-pref[l-1][j]);
        }
        cout << m << endl;
    }

    return 0;
}