#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ff first
#define ss second
#define ll long long
using namespace std;


const int N = 5e5 + 10;
const int B = 30;
int pref[N][B];

int main()
{
    FAST;
    int n, q; cin >> n >> q;
    vector < int > v(n + 1);
    for(int i = 1; i <= n; i++) cin >> v[i];

    for(int i = 1; i <= n; i++)
    {
        int mx = 0;
        for(int j = 1; j < B; j++) if((1<<j)&v[i]) mx = j;

        for(int j = 0; j < B; j++) pref[i][j] = pref[i - 1][j];
        pref[i][mx]++;
    }

    while(q--)
    {
        int l, r; cin >> l >> r;

        int ans = 0;

        for(int i = 0; i < B; i++) ans = max(ans, pref[r][i] - pref[l - 1][i]);
        cout << ans << "\n";
    }


    return 0;
}