#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n,q;
    cin>>n>>q;

    vector<int> br(n+1);
    vector<int> st(34,0);

    vector<vector<int>> a(n+1,vector<int>(n+1));

    int cur_max = 0;

    for(int i=1;i<=n;i++){
        cin>>br[i];
        int stepen = floor(log2(br[i]));
        st[stepen]++;

        if(st[stepen] > cur_max){
            cur_max = st[stepen];
        }

        a[1][i] = cur_max;
    }

    for(int i =1;i<n;i++){

        int stepen = floor(log2(br[i]));
        for(int j=i+1;j<=n;j++){
            int stepen2 = floor(log2(br[j]));
            if(stepen == stepen2){
                a[i+1][j] = max(a[i][j] - 1,1);
                if(j != i+1){
                    a[i+1][j] == max(a[i+1][j], a[i][j]);
                }
            }else{
                a[i+1][j] = a[i][j];
            }
        }

    }

    int x,y;
    while(q--){
        cin>>x>>y;
        cout<<a[x][y]<<'\n';
    }

    return 0;
}