#include <stdio.h>
#include <stdlib.h>
#define ull unsigned long long

ull N,Q;
long A[100005],L,R,K;
long **m;//[100005][100005];

int main()
{
    scanf("%lu%lu",&N,&Q);

    m=(long**)calloc(N,sizeof(long*));

    for(int i=0;i<N;i++)
    {
     m[i]=(long*)calloc(N,sizeof(long));
     scanf("%ld",&A[i]);
    }

    for(int i=0;i<N;i++)
    {
        m[i][i]=A[i];
        for(int j=i+1;j<N;j++) m[i][j]=m[i][j-1] & A[j];
    }
    for(int i=0;i<Q;i++){
     scanf("%ld%ld",&L,&R);
     printf("%ld\n",m[L-1][R-1]);
    }

    return 0;
}