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

using namespace std;

int32_t main()
{
    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]);
    }

    int a[40][n+1];
    int d = 1;

    for(int i = 0; i < mx+1; i++){
        a[i][0] = 0;
        //cout << "0 ";
        for(int j = 1; j < n+1; j++){
            a[i][j] = a[i][j-1] + (v[j-1] == d);
            //cout << a[i][j] << ' ';
        }
        //cout << '\n';
        d+=d;
    }

    int l, r;
    while(q--){
        cin >> l >> r;
        int tr = -1, ans = 1;
        for(int i = 0; i < mx+1; i++){
            tr = a[i][r] - a[i][l-1];
            ans = max(ans, tr);
        }
        cout << ans << '\n';
    }
    return 0;
}