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

#define corner 262143

int n, q;
int st[525000];

int construct(int i)
{
    if(i >= corner){return st[i];}
    return st[i] = construct(i * 2 + 1) & construct(i * 2 + 2);
}

int doIt(int i, int l, int r, int left, int right)
{
    if(l > right || r < left){
        return (1 << 25) - 1;
    }
    else if(l >= left && r <= right){
        return st[i];
    }
    else{
        int mid = (l + r) / 2;
        return doIt(i * 2 + 1, l, mid, left, right) & doIt(i * 2 + 2, mid + 1, r, left, right);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

    for(int i = corner; i <= 524500; ++i){
        st[i] = (1 << 25) - 1;
    }

    cin >> n >> q;

    for(int i = 0; i < n; ++i){
        cin >> st[corner + i];
    }

    construct(0);

    while(q--){
        int left, right;
        cin >> left >> right;
        cout << doIt(0, 0, corner, left - 1, right - 1) << "\n";
    }

    return 0;
}