#include <bits/stdc++.h>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);

    vector<int> a;
    int n, q, x;
    cin >> n >> q;
    int dp[n+2][n+2];
    a.push_back(-1);
    for (int i = 0; i < n; i++) {
        cin >> x;
        a.push_back(x);
    }
    int sol;
    int l,r;
    while (q--) {
        cin >> l >> r;
        sol = a[l];
        for (int i = l+1; i <= r; i++) {
            sol = sol & a[i];
        }
        cout << sol << "\n";
    }
    return 0;
}