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

    int l, r;
    for(int i = 0; i < q; ++i)
    {
        cin >> l >> r;
        l--; r--;
        answers[i] = A[l];
        for(int j = l+1; j <=r; ++j)
        {
            if(A[j] == 1)
            {
                answers[i] == 1;
            }
            if(A[j == 0])
            {
                answers[i] == 0;
                break;
            }
            else
            {
                answers[i] &= A[j];
            }
        }
    }

    for(int i = 0; i < q; ++i)
        cout << answers[i] << endl;

    return 0;
}