#include <iostream>
#include <bits/stdc++.h>
#define print(x) cout << x << endl;
#define show(x) cout << #x << " <=> " << x << endl;
#define show_arr(x, y) cout << #x << ": "; for (int i = 0; i <y; ++i) cout << x[i] << " "; cout << endl;
#define show_vec(x) cout << #x << ": "; for (int i = 0; i < x.size(); ++i) { cout << x[i]; } cout << endl;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, q; cin >> n >> q;
    int arr[200000];
    int precalc[199999];
    vector<int> zeros;
    for (int i = 0; i < n; ++i) cin >> arr[i];
    for (int i = 0; i < n-1; ++i)
        precalc[i] = arr[i] & arr[i+1];
    //show_arr(precalc, n-1);
    for (int i = 0; i < n-1; ++i)
        if (precalc[i]==0) zeros.push_back(i+1);
    //show_vec(zeros);
    while(q--)
    {
        int a, b, c; cin >> a >> b; c = max(a, b); a = min(a, b); b = c;
        //--a, --b;
        bool zr = 0;
        for (int i = 0; i < zeros.size(); ++i)
            if (a<=zeros[i] and b>=zeros[i]+1) zr = 1;
        if (zr) { cout << 0 << '\n'; continue; }
        int res=arr[--a]; --b;
        for (int i = a+1; i < b+1; ++i)
            res &= arr[i];
        cout << res << '\n';
    }
}