#include<iostream>
#include<stdio.h>

using namespace std;

int main()
{
    //ios::sync_with_stdio(false);
    //cin.tie(0);

    unsigned int n, q;

    scanf("%u%u", &n, &q);
    int A[n]; int maxVal = 0;
    int answers[q];
    for(int i = 0; i < n; ++i)
    {
        scanf("%u", &A[i]);
        if(A[i] > maxVal) maxVal = A[i];
    }

    int l, r;

    if(maxVal == 1)
    {
        for(int i = 0; i < q; ++i)
        {
            answers[i] = 1;
            scanf("%u%u", &l, &r);
            l--; r--;
            answers[i] = A[l];
            for(int j = l+1; j <=r; ++j)
            {
                if(A[j] == 0)
                {
                    answers[i] = 0;
                    break;
                }
            }
        }
    }
    else
    {
        for(int i = 0; i < q; ++i)
        {
            scanf("%u%u", &l, &r);
            l--; r--;
            answers[i] = A[l];
            for(int j = l+1; j <=r; ++j)
            {
                answers[i] &= A[j];
            }
        }
    }


    for(int i = 0; i < q; ++i)
    {
        printf("%u", answers[i]);
        printf("\n");
    }

    return 0;
}