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