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

ll niz[200000],novi[200000];

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    ll n,q,p;
    pair <ll,ll> par[10];
    cin >> n >> q;
    for (int i=1;i<=n;i++) cin >> niz[i];

    for (int i=1;i<=q;i++)
    {
        cin >> par[i].first >> par[i].second;
        p=niz[par[i].first];
        for (int j=par[i].first;j<=par[i].second;j++)
        {
            p=(niz[j]&p);
        }
        novi[i]=p;
    }
    for (int i=1;i<=q;i++) cout << novi[i] << '\n';

}