#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

const ull M=1e9*2;

int main()
{
    int n,q; cin >> n >> q;
    vector<int> a(n);

    for(int i=0; i<n; i++)
        cin >> a[i];

    vector<vector<int>> b(M,vector<int>(n,0));
    for(int i=0; i<n; i++){
        ull rr=1;
        while(rr<=a[i]){
            rr*=2;
        }
        rr/=2;
        b[rr][i]=1;
    }
    vector<vector<int>> br(M,vector<int>(n,0));
    ull rr=1;
    while(rr<M){
        br[rr][0]=b[rr][0];
        for(int i=1; i<n; i++)
            br[rr][i]=br[rr][i-1]+b[rr][i];
        rr*=2;
    }
    while(q--){
        int l,r; cin >> l >> r;
        l--;r--;
        int maxx=-1;
        for(ull rr=1; rr<M; rr*=2){
            int sad=br[rr][r];
            if(l>0)sad-=br[rr][l-1];
            maxx=max(maxx,sad);
        }
        cout << maxx << '\n';
    }
    return 0;
}