#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
int a[500002], t[500002][33]; // mzd treba vise od 30
bool pos[500002];
int pref[33][500002], g[500002];
int main()
{
    //koristi zagrade za bitovske operacije
    //proveri jel (1<<30) dovoljno veliko za 10^9
    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 = 0; j <= 30; j++)
        {
            if ((a[i]&(1<<j)) != 0) t[i][j] = 1;
            else t[i][j] = 0;
            //cout << t[i][j] << " ";
        }
        //cout << endl;
    }
    for (i = 1; i <= n; i++)
    {
        pos[i] = false;
    }
    for (j = 30; j >= 0; j--)
    {
        for (i = 1; i <= n; i++)
        {
            if (t[i][j] == 1 && pos[i] == false)
            {
                pos[i] = true;
                g[i] = j;
            }
        }
    }
    // za nule kojih nema ali nmvz
    for (i = 1; i <= n; i++)
    {
        if (!pos[i])
        {
            pos[i] = true;
            g[i] = 31;
        }
    }
    for (j = 0; j <= 31; 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 <= 31; j++)
        {
            res = max(res,pref[j][r]-pref[j][l-1]);
        }
        cout << res << endl;
    }
    return 0;
}
/*
5 3
1 2 1 3 2
1 5
1 4
2 3
*/