#include<iostream>

using namespace std;

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

    unsigned int n, q;

    cin >> n >> q;
    int A[n]; int maxVal = 0;
    int answers[q];
    for(int i = 0; i < n; ++i)
    {
        cin >> 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;
            cin >> 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)
        {
            cin >> 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)
        cout << answers[i] << endl;

    return 0;
}