#include <bits/stdc++.h>
using namespace std;
#define MAX 29
int a[200005];
pair <int, int> b[200005];
int main()
{
    int n, q;
    cin >> n;
    cin >> q;
    for (int i = 1; i <= n; i++)
        cin >> a[i];
    for (int i = 0; i < q; i++)
        cin >> b[i].first >> b[i].second;
    if (q < 1000 && n < 1000) {
        for (int i = 0; i < q; i++) {
            if (b[i].first > b[i].second) {
                cout << 0 << endl;
                continue;
            }
            int resenje = a[b[i].first];
            for (int j = b[i].first + 1; j <= b[i].second; j++) {
                resenje = resenje & a[j];
            }
            cout << resenje << endl;
        }
        return 0;
    }

    return 0;
}