#include <iostream>
#define ll long long

using namespace std;

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

int main()
{

    cin >> n >> q;
    for(int i=0;i<n;++i){
        cin >> a[i];
    }
    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;
}
/*
5 4
1 5 4 3 2
1 3
4 5
2 5
2 3

*/