#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <iomanip>
using namespace std;
int st(long long n) {
    int br = 0;
    while (n > 1) {
        br++;
        n /= 2;
    }
    return br;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    long long n, q;
    cin >> n >> q;
    vector<int> a(n);
    int m = 0;
    for (int i = 0; i < n; i++)
    {
        long long p;
        cin >> p;
        a[i] = st(p);
        m = max(m, a[i]);
    }
    vector<vector<long long>> ps(m+1);
    vector<long long> x(n+1,0);
    for (int i = 0; i < m+1; i++)
    {
        ps[i]=x;
    }
    for (int i = 0; i < m+1; i++)
    {
        for (int j = 1; j < n+1; j++)
        {
            if (a[j-1] == i) ps[i][j]++;
            ps[i][j] += ps[i][j - 1];
        }
    }
    vector<long long> Q(q);
    for (int i = 0; i < q; i++)
    {
        long long r, l;
        cin >> l >> r;
        long long max1 = 0;
        for (int j = 0; j < m+1; j++)
        {
            max1=max(ps[j][r] - ps[j][l-1],max1);
        }
        Q[i] = max1;
    }
    for (int i = 0; i < q; i++)
    {
        cout << Q[i] << endl;
    }
}