#include <iostream>
#include <inttypes.h>
#include <queue>
#include <stdlib.h>
#include <string.h>

using namespace std;


int main()
{
    uint32_t n, q;
    scanf("%"SCNu32 " %"SCNu32, &n, &q);
    uint32_t A[n];
    uint8_t inLastSubset[n];
    for(uint32_t i=0;i<n;i++) {
        scanf("%"SCNu32, &A[i]);
        inLastSubset[i]=0;
    }

    // Podnizovi n^2 resenje
    for(uint32_t i=0;i<q;i++) {
        uint32_t L, R;
        scanf("%" SCNu32 " %" SCNu32, &L, &R);
        uint32_t longestGoodSubset=0;
        uint32_t currentIndex=L-1;
        uint32_t lastElement=A[currentIndex];
        uint32_t currentGoodSubset=0;
        memset(inLastSubset, 0, sizeof(uint8_t)*n);
        for(uint32_t j=currentIndex;j<R;j++) {
            if(inLastSubset[j]) continue;
            currentGoodSubset=0;
            lastElement=A[j];
            for(uint32_t curr=j;curr<R;curr++) {
                if((A[curr]&lastElement)>(A[curr]^lastElement)) {
                    lastElement=A[curr];
                    inLastSubset[curr]=1;
                    currentGoodSubset++;
                }
            }
            if(currentGoodSubset>longestGoodSubset) {
                longestGoodSubset=currentGoodSubset;
            }

        }
        cout << longestGoodSubset << endl;
    }
    return 0;
}