#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];
    vector<int> zeros;
    for (int i = 0; i < n; ++i) cin >> arr[i];
    map<pair<int, int>, bool> alr;
    while(q--)
    {
        int a, b, c; cin >> a >> b; c = max(a, b); a = min(a, b); b = c;
        bool cont = 1;
        for (int i = a-1; i < b; ++i)
        {
            for (int j = i+1; j < b; ++j)
            {
                if (alr[pair<int, int>(arr[i], arr[j])]) { cont = 0; break; }
                else if (arr[i]&arr[j]==0) { alr[pair<int, int>(arr[i], arr[j])]=1; cont = 0; break; }
            }
            if (!cont) break;
        }
        if (!cont) { cout << 0 << '\n'; continue; }
        int res=arr[--a]; --b;
        for (int i = a+1; i < b+1; ++i)
            res &= arr[i];
        cout << res << '\n';
    }
}