#include <iostream>
#include <bits/stdc++.h>

using namespace std;

int And(int a, int b){
    int g = 1, m;
    if(a > b)
        m = b;
    else
        m = a;
    while(m / 2 != 0){
        m /= 2;
        g++;
    }
    int s = 0;
    for(int i = 0; i < g; i++){
        int f = 0;
        if(a%2 == 1 && b%2 == 1){
            f = 1;
            for(int l = 0; l < i; l++){
                f *= 2;
            }
        }
        s += f;
        f = 0;
        a /= 2;
        b /= 2;
        if(a == 0 && b == 0)
            break;
    }
    return s;
}

int main()
{
    int n, q;
    cin >> n;
    cin >> q;
    int niz[n];
    int res[q];
    for(int i = 0; i < n; i++){
        cin >> niz[i];
    }
    for(int j = 0; j < q; j++){
        int l, r;
        cin >> l;
        cin >> r;
        int s;
        s = niz[l-1];
        for(int i = l; i <= r-1; i++){
            s = And(s, niz[i]);
        }
        res[j] = s;
    }
    for(int i = 0; i < q; i++){
        cout << res[i] << endl;
    }
    return 0;
}