#include <bits/stdc++.h>

#define pb push_back

using namespace std;

typedef long long ll;

const int N = 2e5 + 5;
int a[N], nula[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q;
    cin >> n >> q;
    for (int i = 1; i<=n; i++) {
        cin >> a[i];
	
    while (q--) {
        int l, r;
        cin >> l >> r;
        int sol = a[l];
        for (int i = l+1; i<=r; i++)
            sol &= a[i];
        cout << sol << "\n";
    }
    return 0;
}