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

int a[200010];
pair <int, int> b[200010];
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    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;
        cin >> b[i].second;
    }
    for (int i = 0; i < q; i++) {
        int x = 0;
        if (b[i].first > b[i].second) {
            cout << x << 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;
}