#include <stdio.h>
#define max 200010//proveri
    long a[max];
    long funk(long x,long y,long s)
    {
        if(x<=y)
        {
            x++;
            return funk(x,y,s&a[x-1]);
        }
        else return s;
    }
int main()
{
    /*
5 4
1 5 4 3 2
1 3
4 5
2 5
2 3
    */
    long n,q,i,l,r,sol;
    scanf("%ld %ld",&n,&q);
    for(i=1;i<=n;i++)
        scanf("%ld",&a[i]);
        for(i=0;i<q;i++)
        {
            scanf("%ld %ld",&l,&r);
            sol=funk(l+2,r,a[l]&a[l+1]);
            printf("%ld",sol);
        }

}