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