#include <bits/stdc++.h>

using namespace std;

int nadji(int x){
    int c = 1;
    int px = x;
    while(x>0){
        x = x >> 1;
        c++;
    }
    return c-1;
}

int solve(int l, int r, vector<int>& v){
    vector<int> pom(30);
    for(int i = 0; i < 30; i++) pom[i] = 0;
    int maks = -1;
    for(int i = l-1; i < r; i++){
        pom[v[i]]++;
        if(pom[v[i]]>maks){
            maks = pom[v[i]];
        }
    }

    /*for(int i = 0; i < 30; i++){
        cout << pom[i] << " ";
    }
    cout << "\n\n";
    */
    return maks;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int n, q;
    cin >> n >> q;
    vector<int> v;
    for(int i = 0; i < n; i++){
        int x;
        cin >> x;
        v.push_back(nadji(x));
        //cout << nadji(x) << "\n";
    }
    for(int i = 0; i < q; i++){
        int l, r;
        cin >> l >> r;
        cout << solve(l, r, v) << "\n";
    }
    return 0;
}