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

int main()
{
    //ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n, q, max_num=0; cin >> n >> q;
    int arr[200000];
    int precalc[199999];
    vector<int> zeros;
    for (int i = 0; i < n; ++i) {cin >> arr[i];max_num = max(max_num, arr[i]);}
    if (max_num==1||max_num==0)
    {
        if (max_num==0)
        {
            while(q--)
            {
                int a, b, c; cin >> a >> b; c = max(a, b); a = min(a, b); b = c;
                cout << "0\n";
            }

            return 0;
        }
        for (int i = 0; i < n; ++i) { if (arr[i]==0)zeros.push_back(i); }
        while (q--)
        {
            int a, b, c; cin >> a >> b; c = max(a, b); a = min(a, b); b = c;
            --a, --b;
            int index = upper_bound(zeros.begin(), zeros.end(), a-1)-zeros.begin();
            if (b>=zeros[index]) { cout << "0\n"; continue; }
            cout << "1\n";
        }
        return 0;
    }
    for (int i = 0; i < n-1; ++i)
        precalc[i] = arr[i] & arr[i+1];
    for (int i = 0; i < n-1; ++i)
        if (precalc[i]==0) zeros.push_back(i+1);
    while(q--)
    {
        int a, b, c; cin >> a >> b; c = max(a, b); a = min(a, b); b = c;
        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';
    }
}