#include <bits/stdc++.h>
#define int int64_t

using namespace std;

int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int n, q; cin >> n >> q;

    int mx = -1;
    vector<int> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
        if((int)log2(v[i]) > mx) mx = (int)log2(v[i]);
    }
    mx++;

    int a[mx][n+1];
    a[0][0] = 0;
    for(int i = 0; i < n; i++){
        a[0][i+1] = a[0][i] + (v[i] == 1);
    }

    int d = 4;
    for(int i = 1; i < mx; i++){
        a[i][0] = 0;
        for(int j = 1; j <= n; j++){
            a[i][j] = a[i][j-1] + (v[j-1] < d && v[j-1] >= d/2);
        }
        d += d;
    }


    int l, r;
    while(q--){
        cin >> l >> r;

        int tr = 0, ans = -1;
        for(int i = 0; i < mx; i++){
            tr = a[i][r] - a[i][l-1];
            ans = max(ans, tr);
        }

        cout << ans << '\n';
    }

    /*for(int i = 0; i < mx; i++){
        for(int j = 0; j <= n; j++){
            cout << a[i][j] << ' ';
        }
        cout << '\n';
    }*/
    return 0;
}