#include <iostream>

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int n,q;
    cin>>n>>q;
    int a[n+1],b[q],i,j,r,k,x;
    for (int i = 1;i<=n;i++) {
        cin>>a[i];   
    }
        
    for (i = 0;i<q;i++){
        cin>>r>>k;
        x = a[r];
        for (j=r+1;j<=k;j++) {
            if (a[j] == 0) {
               x = 0;
               break;
            }
            else x = x & a[j];
        }
        b[i] = x;
    }
    
    for (i = 0;i<q;i++) {
        cout<<b[i]<<endl;    
    }
    
    return 0;
}