#include <bits/stdc++.h>
#define PRINT(x) cerr<<#x<<"="<<x<<endl
#define pii pair<int,int>
#define fi first
#define se second
#define pb push_back
#define lld long long
#define LINF 1000000000000000000LL
#define mid (l+r)/2
using namespace std;
#define MAXN 200010
int seg[4*MAXN], a[MAXN];
void init(int node, int l, int r) {
    if(l == r) {
        seg[node] = a[l];
        return;
    }
    init(2*node, l, mid);
    init(2*node+1, mid+1, r);
    seg[node] = seg[2*node]&seg[2*node+1];
}
int query(int node, int l, int r, int L, int R) {
    if(L <= l && r <= R) return seg[node];
    int rez = INT_MAX;
    if(L <= mid) rez &= query(2*node, l, mid, L, R);
    if(R > mid) rez &= query(2*node+1, mid+1, r, L, R);
    return rez;
}
int main() {
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);cerr.tie(0);
    int N, Q; cin >> N >> Q;
    for(int i = 1; i <= N; i++) cin >> a[i];
    init(1, 1, N);
    for(int i = 1; i <= Q; i++) {
        int l, r; cin >> l >> r;
        cout << query(1, 1, N, l, r) << endl;
    }
    return 0;
}