#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
int a[500002], pref[33][500002], g[500002];;
bool pos[500002];
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n, q, i, j, brb = 4;
    cin >> n >> q;
    bool bul = true;
    for (i = 1; i <= n; i++)
    {
        cin >> a[i];
        if (a[i] > 8) brb = 30;
        if (a[i] % 2 != 0) bul = false;
    }
    if (bul)
    {
        while (q--)
        {
            int l, r;
            cin >> l >> r;
            cout << 1;
        }
        return 0;
    }
    for (i = 1; i <= n; i++)
    {
        for (j = brb; j >= 0; j--)
        {
            if (pos[i] == false && ((a[i]&(1<<j)) != 0))
            {
                pos[i] = true;
                g[i] = j;
            }
        }
    }
    for (j = 0; j <= brb; j++)
    {
        pref[j][0] = 0;
        for (i = 1; i <= n; i++)
        {
            pref[j][i] = pref[j][i-1];
            if (g[i] == j) pref[j][i]++;
        }
    }
    while (q--)
    {
        int l, r;
        cin >> l >> r;
        int res = 0;
        for (j = 0; j <= brb; j++)
        {
            res = max(res,pref[j][r]-pref[j][l-1]);
        }
        cout << res << endl;
    }
    return 0;
}