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