#include <iostream>

using namespace std;

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