#include <bits/stdc++.h>

using namespace std;

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