#include<bits/stdc++.h>
using namespace std;
int n, m , x, L, R, maks;
int step2 [35];
int dirk[35];
struct s{
    int br;
    int step0;
    int step1;
    int step2;
    int step3;
    int step4;
    int step5;
    int step6;
    int step7;
    int step8;
    int step9;
    int step10;
    int step11;
    int step12;
    int step13;
    int step14;
    int step15;
    int step16;
    int step17;
    int step18;
    int step19;
    int step20;
    int step21;
    int step22;
    int step23;
    int step24;
    int step25;
    int step26;
    int step27;
    int step28;
    int step29;
    int step30;
};
s O[500005];
int main (){
    for(int i=0; i<=30;i++){
        int x=1;
        step2[i]=x<<=i;
    }


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

            scanf("%d",&O[i].br);

                O[i].step0=O[i-1].step0;
                O[i].step1=O[i-1].step1;
                O[i].step2=O[i-1].step2;
                O[i].step3=O[i-1].step3;
                O[i].step4=O[i-1].step4;
                O[i].step5=O[i-1].step5;
                O[i].step6=O[i-1].step6;
                O[i].step7=O[i-1].step7;
                O[i].step8=O[i-1].step8;
                O[i].step9=O[i-1].step9;
                O[i].step10=O[i-1].step10;
                O[i].step11=O[i-1].step11;
                O[i].step12=O[i-1].step12;
                O[i].step13=O[i-1].step13;
                O[i].step14=O[i-1].step14;
                O[i].step15=O[i-1].step15;
                O[i].step16=O[i-1].step16;
                O[i].step17=O[i-1].step17;
                O[i].step18=O[i-1].step18;
                O[i].step19=O[i-1].step19;
                O[i].step20=O[i-1].step20;
                O[i].step21=O[i-1].step21;
                O[i].step22=O[i-1].step22;
                O[i].step23=O[i-1].step23;
                O[i].step24=O[i-1].step24;
                O[i].step25=O[i-1].step25;
                O[i].step26=O[i-1].step26;
                O[i].step27=O[i-1].step27;
                O[i].step28=O[i-1].step28;
                O[i].step29=O[i-1].step29;
                O[i].step30=O[i-1].step30;

                if(O[i].br<step2[1]){
                    O[i].step0++;
                }
                else if(O[i].br<step2[2]){
                    O[i].step1++;
                }
                else if(O[i].br<step2[3]){
                    O[i].step2++;
                }
                else if(O[i].br<step2[4]){
                    O[i].step3++;
                }
                else if(O[i].br<step2[5]){
                    O[i].step4++;
                }
                else if(O[i].br<step2[6]){
                    O[i].step5++;
                }
                else if(O[i].br<step2[7]){
                    O[i].step6++;
                }
                else if(O[i].br<step2[8]){
                    O[i].step7++;
                }
                else if(O[i].br<step2[9]){
                    O[i].step8++;
                }
                else if(O[i].br<step2[10]){
                    O[i].step9++;
                }
                else if(O[i].br<step2[11]){
                    O[i].step10++;
                }
                else if(O[i].br<step2[12]){
                    O[i].step11++;
                }
                else if(O[i].br<step2[13]){
                    O[i].step12++;
                }
                else if(O[i].br<step2[14]){
                    O[i].step13++;
                }
                else if(O[i].br<step2[15]){
                    O[i].step14++;
                }
                else if(O[i].br<step2[16]){
                    O[i].step15++;
                }
                else if(O[i].br<step2[17]){
                    O[i].step18++;
                }
                else if(O[i].br<step2[18]){
                    O[i].step17++;
                }
                else if(O[i].br<step2[19]){
                    O[i].step18++;
                }
                else if(O[i].br<step2[20]){
                    O[i].step19++;
                }
                else if(O[i].br<step2[21]){
                    O[i].step20++;
                }
                else if(O[i].br<step2[22]){
                    O[i].step21++;
                }
                else if(O[i].br<step2[23]){
                    O[i].step22++;
                }
                else if(O[i].br<step2[24]){
                    O[i].step23++;
                }
                else if(O[i].br<step2[25]){
                    O[i].step24++;
                }
                else if(O[i].br<step2[26]){
                    O[i].step25++;
                }
                else if(O[i].br<step2[27]){
                    O[i].step26++;
                }
                else if(O[i].br<step2[28]){
                    O[i].step27++;
                }
                else if(O[i].br<step2[29]){
                    O[i].step28++;
                }
                else if(O[i].br<step2[30]){
                    O[i].step29++;
                }
    }


    for(int i=1 ; i<= m; i++){
        cin>>L>>R;
        maks=0;
        maks=max(O[R].step0-O[L].step0,maks);
        maks=max(O[R].step1-O[L].step1,maks);
        maks=max(O[R].step2-O[L].step2,maks);
        maks=max(O[R].step3-O[L].step3,maks);
        maks=max(O[R].step4-O[L].step4,maks);
        maks=max(O[R].step5-O[L].step5,maks);
        maks=max(O[R].step6-O[L].step6,maks);
        maks=max(O[R].step7-O[L].step7,maks);
        maks=max(O[R].step8-O[L].step8,maks);
        maks=max(O[R].step9-O[L].step9,maks);
        maks=max(O[R].step10-O[L].step10,maks);
        maks=max(O[R].step11-O[L].step11,maks);
        maks=max(O[R].step12-O[L].step12,maks);
        maks=max(O[R].step13-O[L].step13,maks);
        maks=max(O[R].step14-O[L].step14,maks);
        maks=max(O[R].step15-O[L].step15,maks);
        maks=max(O[R].step16-O[L].step16,maks);
        maks=max(O[R].step17-O[L].step17,maks);
        maks=max(O[R].step18-O[L].step18,maks);
        maks=max(O[R].step19-O[L].step19,maks);
        maks=max(O[R].step20-O[L].step20,maks);
        maks=max(O[R].step21-O[L].step21,maks);
        maks=max(O[R].step22-O[L].step22,maks);
        maks=max(O[R].step23-O[L].step23,maks);
        maks=max(O[R].step24-O[L].step24,maks);
        maks=max(O[R].step25-O[L].step25,maks);
        maks=max(O[R].step26-O[L].step26,maks);
        maks=max(O[R].step27-O[L].step27,maks);
        maks=max(O[R].step28-O[L].step28,maks);
        maks=max(O[R].step29-O[L].step29,maks);
        maks=max(O[R].step30-O[L].step30,maks);
        cout<<maks<<endl;
    }

    return 0;
}