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

ll niz[200000],novi[200000];
ll index[200000];

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;
        p=niz[a];
        for (int j=a;j<=b;j++)
        {
            p=(niz[j]&p);
        }
        novi[i]=p;
    }
    for (int i=1;i<=q;i++) cout << novi[i] << '\n';

    return 0;
}