#include<bits/stdc++.h>

using namespace std;

void solve(){
    int n, q;
    cin>>n>>q;
    vector<int> v(n);
    for(int i = 0;i<n;i++) cin>>v[i];
    vector<vector<int>> pref(22, vector<int>(n+1));
    for(int i = 0;i<22;i++){
        pref[i][0] = 0;
        for(int j = 0;j<n;j++){
            pref[i][j+1] = pref[i][j];
            if(((v[j]&(1<<i))>0)&&((v[j])<(1<<(i+1)))) pref[i][j+1]++;
        }
    }
    for(int i = 0;i<q;i++){
        int l, r;
        cin>>l>>r;
        int ans = 0;
        for(int j = 0;j<22;j++){
            ans = max(ans, pref[j][r]-pref[j][l-1]);
        }
        cout<<ans<<endl;
    }
}

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