#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];
    }
    for(int j = 1; j <= q; j++){
        int p = a[ul[j]];
        for(int l = ul[j] + 1; l <= ur[j]; l++){
            p = p & a[l];
        }
        cout << p << '\n';
    }
    delete[] a;
    delete[] ul;
    delete[] ur;
    return 0;
}