#include <bits/stdc++.h>

using namespace std;

const int N = 2e5 + 5;
int nule[N][18];
int jedinice[N][18];

bool lol = 0;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, q, x;
    cin >> n >> q;
    for (int i = 1; i<=n; i++) {
        cin >> x;
        for (int j = 0; j<18; j++)
            jedinice[i][j] = jedinice[i-1][j];
        if (x == 0) {
            lol = 1;
        }
        else if (x == 1) {
            jedinice[i][0]++;
        }
        else {
            int start = 0;
            while (x >= (1 << start)) {
                if (x & (1 << start)) {
                    lol = 1;
                    jedinice[i][start]++;
                }
                start++;
            }

        }
    }

    while (q--) {
        int l, r;
        cin >> l >> r;
        int sol = 0;
        int broj = r - l + 1;
        for (int i = 0; i<=17; i++) {
            int ukupno = jedinice[r][i] - jedinice[l-1][i];
          //  cout << ukupno << " " << broj << endl;
            if (ukupno == broj) {
                sol += (1 << (i));
            }
        }
        cout << sol << endl;
    }
    return 0;
}