#include <bits/stdc++.h>
#define fi first
#define sc second
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define pii pair<int,int>
using namespace std;
typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, q; cin >> n >> q;
    vi a(n+1);
    bool lee = 1;
    for(int i = 1; i <= n; i++){
        cin >> a[i];
        if(a[i] > 8) lee = 0;
        a[i] = 31 - __builtin_clz(a[i]);
    }


    if(lee){
        vector<array<int,5>> oc(n+1, {0,0,0,0,0});
        for(int i = 1; i <= n; i++){
            oc[i] = oc[i-1];
            oc[i][a[i]]++;
        }

        while(q--){
            int l, r; cin >> l >> r;
            array<int,5> res = oc[r];
            for(int i = 0; i < 5; i++) res[i] -= oc[l-1][i];

            int mx = 0;
            for(int i = 0; i < 5; i++) mx = max(mx, res[i]);
            cout << mx << '\n';
        }
    }
    else{
        while(q--){
            int l, r; cin >> l >> r;
            map<int,int> oc;
            int mx = 0;
            for(int i = l; i <= r; i++){
                oc[a[i]]++;
                mx = max(mx, oc[a[i]]);
            }
            cout << mx << '\n';
        }
    }
    return 0;
}