#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;
int sol[N][18];
int main() {
    int n, q, x;
    cin >> n >> q;
    for (int i = 1; i<=n; i++) {
        cin >> x;
        for (int j = 1; j<18; j++ ){
            sol[i][j] = sol[i-1][j];
        }
        if (x == 1) {
            sol[i][1]++;
        }
        if (x <= 1) continue;
        int start = 1;
        while (x >= (1 << start)) {
            if (x & (1 << start)) {
                    sol[i][start]++;
            }
            start++;
        }
    }
    while (q--) {
        int l, r;
        cin >> l >> r;
        int calc = 0;
        int total = r - l + 1;
        for (int i = 1; i<=17; i++) {
            int atm = sol[r][i]-sol[l-1][i];
            if (atm == total)
                calc += (1 << i);
        }
        cout << calc << endl;
    }
}