#include<bits/stdc++.h>
using namespace std;

const int maxN = (int) 2e5 + 5;
const int maxLog = 20;
int n, q;
int a[maxN];
int st[maxN][maxLog];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    cin >> n >> q;
    for(int i = 0; i < n; ++i) {
        cin >> a[i];
        st[i][0] = a[i];
    }
    int k = log2(n);
    for(int j = 1; j <= k; ++j) {
        int poww = (1 << j);
        int powwr = (1 << (j - 1));
        for(int i = 0; i + poww <= n; ++i) {
            st[i][j] = st[i][j - 1] & st[i + powwr][j - 1];
        }
    }

    /*for(int i = 0; i < n; ++i) {
        for(int j = 0; j <= k; ++j) {
            cout << st[i][j] << ' ';
        }
        cout << endl;
    }*/

    for(int T = 1; T <= q; ++T) {
        int l, r;
        cin >> l >> r;
        --l, --r;

        int dist = r - l + 1;
        int pr = -1;
        int ll = l;
        int rez = -1;
        while(dist != 0) {
            pr = log2(dist);
            if(rez == -1)
                rez = st[ll][pr];
            else
                rez &= st[ll][pr];

            dist -= (1 << pr);
            ll += (1 << pr);
        }

        cout << rez << endl;
    }
}