#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);
    }
    for (int i = 1; i <= n; i++)
    {
        for (int j = i; j <= n; j++)
        {
            if (i == j) dp[i][j] = a[j];
            else {
                dp[i][j] = dp[i][j-1] & a[j];
            }
        }
    }
    int l,r;
    while (q--) {
        cin >> l >> r;
        cout << dp[l][r] << "\n";
    }
    return 0;
}