#include <iostream>
#include <cstdio>
using namespace std;
int n, q;
int niz[200005];
int l, r;
//int ST[];
int divlj (int lg, int dg) {
    int ret = niz[lg];
    for (int i = lg + 1; i <= dg; i++) {
        ret &= niz[i];
    }
    return ret;
}
//void construct_tree () {
//
//}
//int brzi_query (int lg, int dg) {
//
//}
int main () {
    scanf("%d %d", &n, &q);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &niz[i]);
    }
    for (int i = 1; i <= q; i++) {
        scanf("%d %d", &l, &r);
        printf("%d\n", divlj(l, r));
    }
    return 0;
}