#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
typedef long long int lint;

int f(int n){
    int c = 1;
    while(n > 1){
        c++;
        n /= 2;
    }
    return c;
}

void solve(){
    int n, q;
    cin >> n >> q;
    vector<int> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
        a[i] = f(a[i]);
    }
    int maksk = 0;
    for(int i = 0; i < n; i++){
        maksk = max(maksk, a[i]);
    }
    vector<vector<int>> pref((maksk + 1), vector<int>(n + 1, 0));
    for(int i = 0; i < n; i++){
        for(int k = 1; k <= maksk; k++){
            pref[k][i + 1] = pref[k][i];
        }
        pref[a[i]][i + 1]++;
    }
    /*
    for(int k = 1; k <= maksk; k++){
        for(int i = 0; i <= n; i++){
            cout << pref[k][i] << " ";
        }
        cout << endl;
    }
    */

    for(int test = 0; test < q; test++){
        int l, r;
        cin >> l >> r;
        l--;
        r--;
        int rez = 0;
        for(int k = 1; k <= maksk; k++){
            rez = max(rez, (pref[k][r + 1] - pref[k][l]));
        }
        cout << rez << endl;
    }
}


signed main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}