#include <stdio.h>

using namespace std;


int main()
{
    bool p = true,w = true;
    int n,q,i,l,r,j,k;
    scanf("%d %d",&n,&q);
    int a[n],h[q];
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
        if(a[i] > 1)
            p = false;
        if(a[i] == 0)
            w = false;
    }
        
    for(i=0;i<q;i++)
    {
        scanf("%d %d",&l,&r);
        h[i] = a[l-1];
        if(n <= 1000 && q <= 1000 && p = false)
        {
            
            while(l < r)
            {
                h[i] = h[i] & a[l];
                l++;
            }
        }
        else
        {
            k = r-1;
            for(j=l;j<(r+l)/2;j++)
            {
                if(a[j] == 0 || a[k] == 0 && w == false)
                {
                    h[i] = 0;
                    break;
                }
                k--;
            }
        }
    }
    for(i=0;i<q;i++)
        printf("%d\n",h[i]);
    return 0;
}