#include <iostream>
#include <bits/stdc++.h>

using namespace std;

#define MAXN 200005

// where is first right set bit from this number
int m[MAXN][20];
int run[20];
int a[MAXN];

int n, q;

void print() {
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < 20; j++) {
            cout << m[i][j] << " ";
        }
        cout << endl;
    }
}

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

    for (int i = 0; i < 20; i++) {
        run[i] = MAXN;
    }

    // prep
    int cur; // this num
    for (int i = n-1; i >= 0; i--) {
        cur = a[i];
        for (int j = 0; j < 20; j++) {
            // this bit is set
            if (!(cur & (1 << j))) {
                run[j] = i; // the first to the right in which this bit is set
            }
            // run is updated after this, now update this num
            m[i][j] = run[j];
        }
    }

    // answer
    int l, r, sum;
    for (int i = 0; i < q; i++) {
        cin >> l >> r;
        l--; r--;
        sum = 0;
        for (int j = 0; j < 20; j++) {
            // the first to the right in which this bit is set is after r, include this bit in sum
            if (m[l][j] > r) {
                //cout << "AAAAAAAAAAAAAAAAAAAAAA";
                sum += (1 << j);
            }
        }
        cout << sum << endl;
    }

    return 0;
}