#include <bits/stdc++.h>
using namespace std;

int a[200005];
int st[800005];

int baseNum = 0;

void build(int id, int l, int r){
    if(l == r){
        st[id] = a[l];
        return;
    }

    int mid = (l + r) / 2;
    build(id * 2 + 1, l, mid);
    build(id * 2 + 2, mid + 1, r);

    st[id] = st[id * 2 + 1] & st[id * 2 + 2];
}

int gSum(int x, int y, int id, int l, int r){
    if(l > y || r < x){
        return baseNum;
    }
    if(x <= l && r <= y){
        return st[id];
    }

    int mid = (l + r) / 2;
    int v1 = gSum(x, y, id * 2 + 1, l, mid);
    int v2 = gSum(x, y, id * 2 + 2, mid + 1, r);

    int res = v1 & v2;
    return res;
}

int main()
{
    int n, t;
    cin >> n >> t;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
    }

    build(0, 0, n - 1);
    for(int i = 0; i <= 31; ++i){ ///MOZDA PREVISE
        baseNum |= (1 << i);
    }

    //cout << baseNum << "\n";
    //return 0;

    while(t--){
        int l, r;
        cin >> l >> r;
        --l;
        --r;
        int x = gSum(l, r, 0, 0, n - 1);
        cout << x << "\n";
    }
    return 0;
}