#include <bits/stdc++.h>

using namespace std;

map <int, int> brojac;

int main()
{
    ios_base::sync_with_stdio(0);
    long long n, q, i, gr1, gr2, j = 0;
    cin >> n >> q;
    bool samodva = true;
    long long niz[n], resenja[q];
    for(i = 0; i < n; i++)
    {
        cin >> niz[i];
        if(niz[i] != 1 || niz[i] != 0) samodva = false;
    }
    if(!samodva)
    {
    for(i = 0; i < q; i++)
    {
        cin >> gr1 >> gr2;
        bool ok = true;
        if(gr1 == gr2)
        {
            resenja[i] = niz[gr1-1];
            ok = false;
        }
        if(ok)
        {
            resenja[i] = niz[gr1] & niz[gr1 - 1];
            for(j = gr1 + 1; j < gr2; j++)
            {
                resenja[i] = resenja[i] & niz[j];
                if(resenja[i] == 0) j = gr2;
            }
        }
    }
    }
    else
    {
        for(i = 0; i < q; i++)
        {
            cin >> gr1 >> gr2;
            brojac[0] = brojac[1] = 0;
            bool ok = true;
            if(gr1 == gr2)
            {
                resenja[i] = niz[gr1-1];
                ok = false;
            }
            if(ok)
            {
                for(j = gr1 - 1; j < gr2; j++)
                {
                    if(niz[j] == 0)
                    {
                        resenja[i] = 0;
                        j = gr2 + 1;
                    }
                    else if(j == gr2 - 1) resenja[i] = 1;
                }
            }
        }
    }
    for(i = 0; i < q; i++)
    {
        if(i != q-1) cout << resenja[i] << endl;
        else cout << resenja[i];
    }
    return 0;
}