#include <bits/stdc++.h>
#define int long long
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),x.end()
#define fi first
#define sc second
#define pii pair<int,int>
#define endl "\n"

using namespace std;

const int lg = 30;

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,q;cin >> n >> q;
    vector<int> niz(n);
    for(int i=0; i<n; i++)cin >> niz[i];
    vector<vector<int>> mat(lg, vector<int>(n+1,0));
    for(int i=0; i<n; i++)
    {
        for(int j=lg-1; j>=0; j--)
        {
            if(niz[i] - (1<<j) >= 0)
            {
                mat[j][i+1]=1;
                break;
            }
        }
    }
    for(int i=0; i<lg; i++)
    {
        for(int j=1; j<=n; j++)
        {
            mat[i][j] += mat[i][j-1];
        }
    }
    //int q;cin >> q;
    while(q--)
    {
        int l,r;cin >> l >> r;
        int rez = 0;
        for(int i=0; i<lg; i++)
        {
            rez = max(rez, mat[i][r] - mat[i][l-1]);
        }
        cout << rez << endl;
    }
}