#include<iostream>
#include<cstdio>
using namespace std;
#define SVEJEDINICE 524287 ///ovo
int gmin, gmax, niz[1000000], a[1000000];
int n, q, l, r;
int kreiraj(int i){

    if(i >= gmin and i <= gmax){
        niz[i] = a[i - gmin + 1];
        //cout << "T1 i = " << i << " niz[i] = " << niz[i] << endl;
        return niz[i];
    }
    else if(i >= gmax){
        //cout << "T2 i = " << i << endl;
        return SVEJEDINICE;
    }
    else{
        //if(i * 2 > gmax and i * 2 + 1 > gmax)
        int p = kreiraj(i * 2);
        int q = kreiraj(i * 2 + 1);
        int r = p & q;
        //cout << "T3 i = " << i << " p = " << p << " q = " << q << " r = " << r << endl;
        niz[i] = r;
        return r;
    }

}
int trazi(int li, int ri, int i){ /// konvertuj, l+= gmin r+=gmin

    //cout << "E i = " << i << endl;
    if(li >= l and ri <= r){
        //cout << "P1 i = " << i << " li = " << li << " ri = " << ri << endl;
        return niz[i];
    }
    else if(ri < l or li > r){
           // cout << "P2 i = " << i << endl;
            return SVEJEDINICE;
        }
    else{
        int p = trazi(li, li + (ri - li) / 2, i * 2);
        int q = trazi(li + (ri - li) / 2 + 1, ri, i * 2 + 1);
        int r = (p & q);
       // cout << "P3 i = " << i << " p = " << p << " q = " << q << " r = " << r << endl;
        return r;
    }

}
int stepen(int osnova, int eksponent){
    int rez = 1;
    for(int i = 1; i <= eksponent; i++)
        rez *= osnova;
    return rez;
}
int main(){

    //freopen("ulaz.txt", "r", stdin);
    //freopen("izlaz.txt", "w", stdout);
    cin >> n >> q;
    for(int i = 1; i <= n; i++)
        cin >> a[i];

    int dvica = 0;
    while(1){
        if(stepen(2, dvica) >= n)
            break;
        dvica++;
    }
    for(int j = 0; j <= dvica; j++)
        gmax += stepen(2, j);
    gmax -= stepen(2, dvica) - n;
    gmin = stepen(2, dvica);

    //cout << "gmin = " << gmin << " gmax = " << gmax << endl;


    kreiraj(1);
    //for(int i = 1; i <= gmax; i++)
    //    cout << niz[i] << " ";
    //cout << endl;
    for(int i = 1; i <= q; i++){
        cin >> l >> r;
        //cout << "rez = " << trazi(1, stepen(2, dvica), 1) << endl;
        cout << trazi(1, stepen(2, dvica), 1) << endl;
    }


    return 0;
}