#include <bits/stdc++.h>
using namespace std;
int n,q,a[200005],L,R,x,pref[200005];
bool drugi,t;
int main () {
scanf("%d%d",&n,&q);
drugi=true;
for (int i=1;i<=n;i++){
    scanf("%d",&a[i]);
    if (a[i]>1){drugi=false;}
    pref[i]=pref[i-1]+a[i];
}
 if (drugi){
     for (int i=1;i<=q;i++){
         scanf("%d%d",&L,&R);
         if (pref[R]-pref[L-1]==R-L+1){
            printf("1\n");}
         else {printf("0\n");}
     }
}
else if (n<=1000 and q<=1000){

    for (int i=1;i<=q;i++){
        scanf("%d%d",&L,&R);
        x=a[L];
        for (int j=L+1;j<=R;j++){
            x&=a[j];
        }
        printf("%d\n",x);
    }
}
else {}
return 0;
}