#include <bits/stdc++.h>

using namespace std;

#define ll long long
const int INF=1e9;
const ll LINF=1e18;
#define kec first.second
#define dva first.fi
#define idx second
#define fi first
#define se second
#define Blok pair<pair<long long,long long>,int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mid ((l+r)/2)
#define sz(a) (int((a).size()))
#define all(a) a.begin(),a.end()
#define endl "\n"
#define pb push_back

void PRINT(int x) {cerr << x;}
void PRINT(ll x) {cerr << x;}
void PRINT(double x) {cerr << x;}
void PRINT(char x) {cerr << '\'' << x << '\'';}
void PRINT(string x) {cerr << '\"' << x << '\"';}
void PRINT(bool x) {cerr << (x ? "true" : "false");}

template<typename T,typename V>
void PRINT(pair<T,V>& x){
    cerr<<"{";
    PRINT(x.fi);
    cerr<<",";
    PRINT(x.se);
    cerr<<"}";
}
template<typename T>
void PRINT(T &x){
    int id=0;
    cerr<<"{";
    for(auto _i:x){
        cerr<<(id++ ? "," : "");
        PRINT(_i);
    }
    cerr<<"}";
}
void _PRINT(){
    cerr<<"]\n";
}
template<typename Head,typename... Tail>
void _PRINT(Head h,Tail... t){
    PRINT(h);
    if(sizeof...(t)) cerr<<", ";
    _PRINT(t...);
}

#define Debug(x...) cerr<<"["<<#x<<"]=["; _PRINT(x)

const int mxN=500000;
const int LOG=30;
int A[mxN+1];
int max_bit[4*mxN+1];
vector<int> poz[LOG+1];

void Solve(){
    int N,Q; cin>>N>>Q;
    vector<int> A(N+1);
    for(int i=1;i<=N;i++) cin>>A[i];
    for(int i=1;i<=N;i++){
        for(int b=0;b<=LOG;b++){
            if((1<<b)&A[i]){
                max_bit[i]=max(max_bit[i],b);
            }
        }
        poz[max_bit[i]].pb(i);
    }
    for(int q=1;q<=Q;q++){
        int L,R; cin>>L>>R;
        int res=0;
        for(int b=0;b<=LOG;b++){
            if(!sz(poz[b])) continue;
            int L1=-1,R1=-1;
            int l=0,r=sz(poz[b])-1;
            while(l<=r){
                if(poz[b][mid]>=L){
                    L1=mid;
                    r=mid-1;
                }
                else{
                    l=mid+1;
                }
            }
            l=0,r=sz(poz[b])-1;
            while(l<=r){
                if(poz[b][mid]<=R){
                    R1=mid;
                    l=mid+1;
                }
                else r=mid-1;
            }
            if(L1!=-1 && R1!=-1) res=max(res,R1-L1+1);
        }
        cout<<res<<endl;
    }
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    int t; t=1; //cin>>t;
    while(t--){
        Solve();
    }
    return 0;
}