#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <bits/stdc++.h>
#include <strstream>
#include <queue>

#define USE_MATH_DEFINES

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    long long int n, q, i, u, l, r, z, j;
    cin>>n>>q;
    long long int* a= new long long int [n+2];
    long long int* b= new long long int [q+2];
    for (i=1; i<=n; i++) {
        cin>>a[i];
    }
    for (i=1; i<=q; i++) {
        cin>>l>>r;
        b[i]=a[l];
        for (j=l+1; j<=r; j++) {
            b[i]=b[i]&a[j];
        }
    }
    for (i=1; i<=q; i++) {
        cout<<b[i];
        if (i!=q) {
            cout<<"\n";
        }
    }
    delete[]a;
    delete[]b;
    return 0;
}