#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n, q;
vector<ll> a;
/*ll setbit(ll a)
{
    ll m=1, ans=0;
    while (m<=a){
        if ((m&a)==m) ans++;
        m<<=1;
    }
    return ans;
}*/

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> q;
    a.resize(n+2);
    for (ll i=0;i<n;i++) cin >> a[i];
    while (q--){
        ll l, r; cin >> l >> r;
        set<ll> s;
        l--;r--;
        map<ll, ll> m;
        for (ll i=l;i<=r;i++){
            s.insert(a[i]);
            m[a[i]]++;
        }
        if (s.size()==1) {cout << r-l+1 << '\n'; continue;}
        ll ans=0;
        for (ll i:s){
            for (ll j:s){
                if (i==j) {ans=max(ans, m[i]); continue;}
                if (((i&j)>(i^j))) ans=max(ans, (m[i]+m[j]));
            }
        }
        cout << ans << '\n';
    }
    /*
    bool stepen=true;
    map<ll, ll> m;
    ll maks=LLONG_MIN;
    for (ll i=0;i<n;i++){
        cin >> a[i];
        m[a[i]]++;
        maks=max(maks, m[a[i]]);
        if (setbit(a[i])!=1) stepen=false;
    }
    //cout << m[2] << " " << m[4] << " " << m[8] << '\n';
    while (q--){
        ll l, r; cin >> l >> r;
        l--; r--;
        ans=LLONG_MIN;
        vector<ll> v;
        najduzi(l, r, v);
        v.push_back(a[l]);
        najduzi(l, r, v);
        cout << ans << '\n';
        //if (stepen) cout << maks << '\n';
    }*/
    return 0;
}