#include <bits/stdc++.h>

using namespace std;

unsigned a[200005];
int b[200005][2];

void prtbits(unsigned x)
{
    unsigned a;
    for(a = 1<<(sizeof(unsigned)*8-1); a; a>>=1)
    {
        if(a&x) cout << 1;
        else cout << 0;
    }
    cout << endl;
}

int main()
{
    ios::sync_with_stdio(false); cin.tie(0);
    int n, q, l, r;
    unsigned g;
    cin >> n >> q;
    for(int i = 1; i<=n; i++)
        cin >> a[i];
    for(int i = 1; i<=q; i++)
    {
        cin >> b[i][0] >> b[i][1];
    }
    for(int i = 1; i<=q; i++)
    {
        g=~(0);
        //prtbits(g);
        //cout << g;
        for(int j = b[i][0]; j<=b[i][1]; j++)
        {
            //cout << (a[j]&(~(0))) << endl;
            g=g&a[j];
        }
        cout << g << endl;
    }
    return 0;
}