#include <bits/stdc++.h>

using namespace std;


//Ogranicenja:
//1 <= N, Q <= 5 * 10 ^ 5;
//1 <= Ai <= 10 ^ 9
//1 <= L <= R <= N

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, q; cin >> n >> q;
    vector<long long> a;
    vector<long long> s;


    for(int i = 0; i < n; i++){
        int p; cin >> p;
        a.push_back(p);
    }

    for (int k = 0; k < q; k++){
        int l, r; cin >> l >> r;
        l--; r--;

        int duzina = 0;

        //cout << "Pod niz: "
        //for (int p = l; p < r; p++)cout << s[p] << " ";

        //cout << "Prvi element je: " << a[l] << " a zadnji je: " << a[r] << '\n';
        for (int i = l; i <= r; i++){
            for (int j = i; j <= r; j++){
                if ((a[i] & a[j]) > (a[i] ^ a[j]))s.push_back(a[i]);
                
            }
            if (s.size() > duzina)duzina = s.size();
            //cout << "Niz: ";
            //for (int p = 0; p < s.size(); p++)cout << s[p] << " ";
            //cout << " Ima dimenziju: " << s.size() << '\n';
            s = {};
        }
        
        //cout << "Niz: ";
        //for (int p = 0; p < s.size(); p++)cout << s[p] << " ";
        //cout << " Ima dimenziju: " << s.size() << '\n';
        //s = {};

        cout << duzina << '\n';

    }

    

    return 0;
}