#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){
ios_base::sync_with_stdio(NULL);
cin.tie(nullptr);
long long n,q;
cin >> n >> q;
long long a[n];
vector<vector<long long>> b;
for(long long i=0;i<n;i++){
    cin >> a[i];
    bool prv=false;
    for(long long j=0;j<b.size();j++){
        bool pr=true;
        for(long long k=0;k<b[j].size();k++){
                long long I=(a[b[j][k]] & a[i]);
                long long X=(a[b[j][k]] ^ a[i]);
            if(I<X){
                   // cout << "BREAK "  << a[b[j][k]] << " " << a[i] << endl;
                pr=false;
                break;
            }
           // else cout << " nije break zato sto je " << I << "<" << X << endl;
        }
        if(pr){
            prv=true;
            b[j].push_back(i);
           // cout << " dodat je " << a[i] << " u " << j << " " <<(a[i]&a[b[j][0]]) << " " << (a[i]^a[b[j][0]])  << endl;
        }
    }
    if(!prv){
        vector<long long> c;
        c.push_back(i);
        b.push_back(c);
       // cout << " napravljen novi za " << a[i] << " " << b.size()-1 << endl;
    }
   //cout << "stanje" << endl;
//for(int i=0;i<b.size();i++){ for(int j=0;j<b[i].size();j++) cout << a[b[i][j]] << " ";
//cout << endl;
//}
}
//cout << "stanje" << endl;
//for(int i=0;i<b.size();i++){ for(int j=0;j<b[i].size();j++) cout << a[b[i][j]] << " ";
//cout << endl;
//}
while(q){
    q--;
    long long l,r;
    cin >> l >> r;
    l--;
    r--;
    long long re=0;
    for(long long i=0;i<b.size();i++){
        long long pr=b[i].size();
        long long p1=0,p2=pr-1;
        if(b[i][p1]>r || b[i][p2]<l)continue;
        while(b[i][p1]<l || b[i][p2]>r){
            if(pr<=1)break;
            if(b[i][p1]<l){
                p1++;
            pr--;
            }
            if(b[i][p2]>r){
            p2--;
            pr--;
            }
        }
       // cout << re << " pre menjanja "  << endl;
        re=max(re,pr);

    }
    cout << re << "\n";
}
cout << "\n";
return 0;
}