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

int main()
{
    ll q,n;
    scanf("%ll%ll",&q,&n);
    ll niz[n];
    ll l,r;
    for(ll i=0;i<n;i++) scanf("%ll",&niz[i]) ;
    ll resenje[q];
    for(ll i=0;i<q;i++)
    {
        scanf("%ll%ll",&l,&r);
        l--;
        r--;
        resenje[i]=INT_MAX;
        for(ll j=l;j<=r;j++)
        {
            resenje[i] = resenje[i]&niz[j];
            if(resenje[i]==0)break;
        }
    }
    for(ll i=0;i<q;i++)
    {
        printf("%ll",resenje[i]);
    }
}