#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
int a[500002], pref[33][500002], g[500002];;
bool pos[500002];
int main()
{
    int n, q, i, j;
    cin >> n >> q;
    for (i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    for (i = 1; i <= n; i++)
    {
        for (j = 30; j >= 0; j--)
        {
            if ((a[i]&(1<<j)) != 0)
            {
                if (pos[i] = false)
                {
                    pos[i] = true;
                    g[i] = j;
                }
            }
            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 <= 30; j++)
        {
            res = max(res,pref[j][r]-pref[j][l-1]);
        }
        cout << res << endl;
    }
    return 0;
}