#include <bits/stdc++.h>
#define ll long long
using namespace std;

ll niz[200000],novi[200000];
ll matrica[200000][3];

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

    ll n,q,p,a,b;
    cin >> n >> q;
    for (int i=1;i<=n;i++) cin >> niz[i];

    for (int i=1;i<=q;i++)
    {
        cin >> a >> b;
        if (matrica[a][1]!=0 && matrica[a][2]<=b)
        {
            p=matrica[a][3];
            for (int j=matrica[a][2];j<=b;j++) p=(niz[j]&p);
        }
        else
        {
            matrica[a][1]=a;
            matrica[a][2]=b;
            p=niz[a];
            for (int j=a;j<=b;j++)
            {
                p=(niz[j]&p);
            }
            novi[i]=p;
            matrica[a][3]=p;
        }
    }
    for (int i=1;i<=q;i++) cout << novi[i] << '\n';
    /*for (int i=1;i<=4;i++)
    {
        for (int j=1;j<=3;j++) cout << matrica[i][j] << " ";
        cout << endl;
    }*/
    return 0;
}