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

using namespace std;

int And(int a, int b){
    if(a == 1 && b == 1)
        return 1;
    if(a == 0 && b == 0)
        return 0;
    if(a == 0 && b == 1)
        return 0;
    if(a == 1 && b == 0)
        return 0;
    int g = 1, m;
    if(a > b)
        m = b;
    else
        m = a;
    while(m / 2 != 0){
        m /= 2;
        g++;
    }
    long 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()
{
    long n, q;
    cin >> n;
    cin >> q;
    long niz[n];
    int res[q];
    for(int i = 0; i < n; i++){
        cin >> niz[i];
    }
    for(int j = 0; j < q; j++){
        long l, r;
        cin >> l;
        cin >> r;
        long 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;
}