#include <iostream>
#define ll long long

using namespace std;

int n,q,l,r;
ll a[200005];
int cnt[200005];
ll res;

int main()
{

    cin >> n >> q;
    for(int i=0;i<n;++i){
        cin >> a[i];
        if(!i){
            res=a[i];
            cnt[i]=!(a[i]);
            continue;
        }
        cnt[i]=cnt[i-1]+(a[i]==0);
    }

   bool b=true;
    for(int i=0;i<n;++i){
        if(a[i]>1){b=false;break;}
    }
   /* for(int i=0;i<n;++i){
        cout << cnt[i] << " ";
    }*/
    //cout << endl;
    if(b){
        while(q--){
            cin >> l >> r;
            --l;--r;
            //cout << l << " " << r << endl;
            //cout << cnt[r] << " " << cnt[l] << endl;
            if(a[l]==0){
                //cout << 'A' << " ";
                if(cnt[r]-cnt[l]+1==0){
                    cout << 1 << endl;
                }else{
                  cout << 0 << endl;
                }
            }else{
               //cout << a[r] << " " << a[l] << endl;
              // cout << 'B' << " " << cnt[r]-cnt[l] << endl;
               if(cnt[r]-cnt[l]==0){
                cout << 1 << endl;
               }else{
                 cout << 0 << endl;
               }
            }
        }
        return 0;
    }
    while(q--){
        cin >> l >> r;
        --l;--r;
        res=a[l];
        for(int i=l+1;i<=r;++i){
           res=(res & a[i]);
         //  cout << a[i] << " ";
          // cout << res << endl;
        }
        cout << res << endl;
      }
    return 0;
}