#include<cstdio>
#include<vector>
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#define lld long long
#define pb push_back
using namespace std;
int tree[800010],n,q,a[200010];
void build(int x,int l,int r){
   if(l==r){
    tree[x]=a[l];
    return;
   }
   int mid=(l+r)/2;
   build(x*2,l,mid);
   build(x*2+1,mid+1,r);
   tree[x]=(tree[x*2]&tree[x*2+1]);
}
int query(int x,int l,int r,int ll,int rr){
   if(l>=ll & r<=rr)return tree[x];
   int mid=(l+r)/2;
   if(rr<=mid)return query(x*2,l,mid,ll,rr);
   else if(ll>mid)return query(x*2+1,mid+1,r,ll,rr);
   else return (query(x*2,l,mid,ll,rr)&query(x*2+1,mid+1,r,ll,rr));
}
int main(){

    scanf("%d %d",&n,&q);
    for(int i=1;i<=n;i++)scanf("%d",&a[i]);
    build(1,1,n);

    for(int i=1;i<=q;i++){
        int l,r;
        scanf("%d %d",&l,&r);
        printf("%d\n",query(1,1,n,l,r));
    }



return 0;
}