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

using namespace std;

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

    // Podnizovi
    for(uint32_t i=0;i<q;i++) {
        uint32_t L, R;
        queue<uint32_t> q;
        scanf("%"SCNu32 " %"SCNu32, &L, &R);
        // Dodamo u queue one koji nisu u dobrom nizu (za pocetak dodajemo 0. index)
        q.push(L-1);
        uint32_t longestGoodSubset=0;
        while(q.empty()==false) {
            uint32_t currentIndex=q.front();
            uint32_t lastElement=A[currentIndex];
            uint32_t currentGoodSubset=0;
            q.pop();
            for(uint32_t curr=currentIndex;curr<R;curr++) {
                            //printf("current = A[%u] = %u\nLast element = %u\n", curr, A[curr], lastElement);
                if((A[curr]&lastElement)>(A[curr]^lastElement)) {
                    lastElement=A[curr];
                    currentGoodSubset++;
                            //printf("Changed last element to %u\n", lastElement);
                }
                else {
                            //printf("Pushed back %u\n", curr);
                    q.push(curr);
                }
            }
            if(currentGoodSubset>longestGoodSubset) {
                longestGoodSubset=currentGoodSubset;
            }
        }
        cout << longestGoodSubset << endl;
    }
    return 0;
}