#include <iostream>

using namespace std;


int main()
{
    int n,q,i,l,r;
    cin >> n >> q ;
    int a[n],h[q];
    for(i=0;i<n;i++)
        cin >> a[i];
    for(i=0;i<q;i++)
    {
        cin >> l >> r;
        h[i] = a[l-1];
        while(l < r)
        {
            h[i] = h[i] & a[l];
            l++;
        }
    }
    for(i=0;i<q;i++)
        cout << h[i] << endl;
    return 0;
}