#include <bits/stdc++.h>
using namespace std;
long long n, q, x, y, maks, MAKS;
long long a[500005];
int main(){
    scanf("%lld%lld", &n, &q);
    for(int i = 1; i <= n; i++){
        cin >> a[i];
    }
    for(int k = 1; k <= q; k++){
        maks = 0;
        MAKS = 0;
        scanf("%lld%lld", &x, &y);
        for(int i = x; i <= y; i++){
            maks = 0;
            for(int j = x; j <= y; j++){
                if((a[i]&a[j])>(a[i]^a[j])) maks++;
            }
            if(maks > MAKS) MAKS = maks;
        }
        cout<<MAKS<<endl;
    }
return 0;
}