#include <bits/stdc++.h>

using namespace std;

int br[200005][50];

int calc(int n, int i) {

    int b = 0;
    while(n > 0) {
        if(i == 0) {
            if(n % 2 == 1)
                br[i][b] = 0;
        } else {
            if(n % 2 == 0)
                br[i][b] = br[i - 1][b] + 1;
            else
                br[i][b] = br[i - 1][b];
        }
        b++;
        n /= 2;

        if(n == 0)
            for(int j = 0; j < 10; j++)
                br[i][b + i] = br[i - 1][b + i];
    }

    return b;
}

void run(int q, int x) {

    for(int i = 0; i < q; i++) {
        int l, r;
        cin >> l >> r;

        int sol = 0, d = 1;
        for(int j = 0; j < x; j++) {
            if((l == 1 && br[r - 1][j] == 0) || (l > 1 && br[r - 1][j] - br[l - 2][j] == 0))
                sol += d;

            d *= 2;
        }

        cout << sol << endl;
    }
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

    int n, q;
    cin >> n >> q;

    int a[n];

    int x = 0;

    for(int j = 0; j < 50; j++) {
        br[0][j] = 1;
    }


    for(int i = 0; i < n; i++) {
        cin >> a[i];
        x = max(x, calc(a[i], i));
    }

    run(q, x);
    return 0;
}