#include <bits/stdc++.h>
#define ll long long
#define endl '\n'
#define MAXN 500005

using namespace std;

vector <int> A(MAXN), prvi_bit(MAXN);
vector < vector <int> > pref(31, vector <int> (MAXN));

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0);
    int N, Q;
    cin >> N >> Q;
    for(int i = 1; i <= N; i++) cin >> A[i];
    for(int i = 1; i <= N; i++)
    {
        int val = A[i];
        for(int bit = 30; bit >= 0; bit--)
        {
            if(val&(1 << bit))
            {
                prvi_bit[i] = bit;
                break;
            }
        }
    }
    for(int i = 1; i <= N; i++)
    {
        int bit = prvi_bit[i];
        pref[bit][i]++;
    }
    for(int bit = 30; bit >= 0; bit--)
    {
        for(int i = 1; i <= N; i++) pref[bit][i] += pref[bit][i - 1];
    }
    while(Q--)
    {
        int L, R, maks = 1;
        cin >> L >> R;
        for(int bit = 30; bit >= 0; bit--)
        {
            maks = max(maks, pref[bit][R] - pref[bit][L - 1]);
        }
        cout << maks << endl;
    }
    return 0;
}