#include <iostream>

using namespace std;

int n, q;
int a[200005];
int STree[1000000];

void buildST(int l, int r, int index){
    if (l == r){
        STree[index] = a[l];
        return;
    }
    buildST(l, (l+r)/2, 2 * index + 1);
    buildST((l+r)/2+1, r, 2 * index + 2);

    STree[index] = STree[2 * index + 1] & STree[2 * index + 2];
}

int findST(int l, int r, int trl, int trr, int index){
    if (trl >= l && trr <= r)
        return STree[index];
    if (trl > r || trr < l)
        return 1048575;
    return findST(l, r, trl, (trl + trr)/2, 2*index + 1) & findST(l, r, (trl + trr)/2 + 1, trr, 2*index + 2);
}

int main()
{
    cin >> n >> q;
    for (int i = 0; i < n; ++i)
        cin >> a[i];
    buildST(0, n-1, 0);
    for (int i = 0; i < q; ++i){
        int l, r;
        cin >> l >> r;
        cout << findST(l-1, r-1, 0, n-1, 0) << endl;
    }
    return 0;
}