#include <iostream>

using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    int q;
    cin >> n;
    cin >> q;
    int *a = new int[n + 1];
    for(int  i = 1; i <= n; i++){
        cin >> a[i];
    }
    int *ul = new int[q + 1];
    int *ur = new int[q + 1];
    for(int h = 1; h <= q; h++){
        cin >> ul[h];
        cin >> ur[h];
    }
    int *maks = new int[n + 1];
    for(int h = 1; h < n; h++){
        maks[h] = 0;
    }
    for(int j = 1; j <= n; j++){
        if(maks[ul[j]] < ur[j]) maks[ul[j]] = ur[j];
    }
    int **m = new int*[n + 1];
    for(int s = 1; s <= n; s++){
        m[s] = new int[maks[s] + 1];
        m[s][1] = a[s] & a[s];
        if(s < maks[s]) m[s][2] = a[s] & a[s + 1];
        if(s < maks[s] - 1){
            for(int l = 3; l <= n + 1 - s; l++){
                m[s][l] = m[s][l - 1] & a[s + l - 1];
            }
        }
    }
    for(int l = 1; l <= q; l++){
        cout << m[ul[l]][ur[l] - ul[l] + 1] << '\n';
    }
    delete[] a;
    delete[] m;
    delete[] ul;
    delete[] ur;
    delete[] maks;
    return 0;
}