#include <bits/stdc++.h>
using namespace std;
int n,q,a[200005],L,R,x,nule[200005],br;
bool drugi,t;
int main () {
scanf("%d%d",&n,&q);
drugi=true;
br=1;
for (int i=1;i<=n;i++){
    scanf("%d",&a[i]);
    if (a[i]>1){drugi=false;}
    if (a[i]==0){nule[br]=i;br++;}
}
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 if (drugi){

     for (int i=1;i<=q;i++){
         scanf("%d%d",&L,&R);
         t=false;
           for (int j=1;j<br;j++){
               if (nule[j]>=L and nule[j]<=R){
                t=true;
                break;
               }
           }
            if (t){printf("0\n");}
            else {printf("1\n");}
     }
}
else {}
return 0;
}