#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;
        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;
        }
    }
    for(i = 0; i < q; i++)
    {
        if(i != q-1) cout << resenja[i] << endl;
        else cout << resenja[i];
    }
    return 0;
}