#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define si short int
#define vi vector<ll>
#define vii vector<vi>
#define vip vector<pair<ll,ll>>

ll resi(ll a[], ll n, ll l, ll r);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll n,q;
    cin>>n>>q;
    ll a[n+1];
    for(ll i=1;i<=n;i++)
        cin>>a[i];
    for(ll i=0;i<q;i++)
    {
        ll l,r;
        cin>>l>>r;
        cout<<resi(a,n,l,r)<<endl;
    }
    return 0;
}

ll resi(ll a[], ll n, ll l, ll r)
{
    ll kon=a[l]&a[l+1];
    for(ll i=l+2;i<=r;i++)
        kon=kon&a[i];
    return kon;
}