#include<stdio.h>
main()
{
    int n,q,i,l,r,p;
    scanf("%d%d",&n,&q);
    int a[n],resenje[q];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(p=0;p<q;p++)
    {
        scanf("%d%d",&l,&r);
        for(i=l;i<r;i++)
        {
            if(resenje[p]!=0)
                resenje[p]=resenje[p]&a[i-1];
            else
                resenje[p]=a[i-1]&a[i];
        }
    }
    for(p=q-1;p>=0;p--)
    {
        printf("%d\n",resenje[p]);
    }
    /*printf("\n\nPrvi upit: %d",a[0]&a[1]&a[2]);
    printf("\n\nDrugi upit: %d",a[3]&a[4]);
    printf("\n\nTreci upit: %d",a[1]&a[2]&a[3]&a[4]);
    printf("\n\nCetvrti upit: %d",a[1]&a[2]);*/
}