#include <iostream>
#include <cstdio>
using namespace std;
int n, q;
int niz[200005];
int l, r;
int ST[2000005];
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 lg, int dg, int pos) {
    if (lg == dg) {
        ST[pos] = niz[lg];
        return;
    }

    int mid = (lg + dg) / 2;

    construct_tree(lg     , mid, pos * 2    );
    construct_tree(mid + 1, dg , pos * 2 + 1);

    ST[pos] = ST[pos * 2] & ST[pos * 2 + 1];
}
int brzi_query (int lg, int dg, int tl, int td, int pos) {
    /// SKROZ U INTERVALU
    if (tl >= lg && td <= dg) {
        return ST[pos];
    }
    /// ISPADA IZ INTERVALA
    if (tl > dg || td < lg) {
        return -1;
    }
    /// DELIMICNO U INTERVALU
    int mid = (tl + td) / 2;
    int a = brzi_query(lg, dg, tl, mid, pos * 2);
    int b = brzi_query(lg, dg, mid + 1, td, pos * 2 + 1);
    if (a == -1) a = b;
    if (b == -1) b = a;
    return a & b;
}
int main () {
    scanf("%d %d", &n, &q);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &niz[i]);
    }
    construct_tree(1, n, 1);
    for (int i = 1; i <= q; i++) {
        scanf("%d %d", &l, &r);
//        printf("%d\n", divlj(l, r));
        printf("%d\n", brzi_query(l, r, 1, n, 1));
    }
    return 0;
}