#include <bits/stdc++.h>
using namespace std;
const int N = 55555;
const int A = 1111111;
int n, m;
int a[N];
int cum_xor[A];
int l[N], r[N], b[N], ans[N];
void solve() {
  cum_xor[0] = 0;
  for (int i = 1; i < A; ++i) cum_xor[i] = cum_xor[i - 1] ^ i;
  assert(scanf("%d %d", &n, &m) == 2);
  for (int i = 0; i < n; ++i) assert(scanf("%d", &a[i]) == 1);
  for (int i = 0; i < m; ++i) {
    assert(scanf("%d %d", &l[i], &r[i]) == 2);
    --l[i];
    --r[i];
  }
  for (int i = 0; i < n; ++i) {
    int best = 0;
    for (int j = i; j < n; ++j) {
      int curr = cum_xor[a[i]] ^ cum_xor[a[j]] ^ min(a[i], a[j]);
      if (curr > best) best = curr;
      b[j] = best;
    }
    for (int k = 0; k < m; ++k) {
      if (l[k] <= i && i <= r[k]) {
        ans[k] = max(ans[k], b[r[k]]);
      }
    }
  }
  for (int i = 0; i < m; ++i) printf("%d\n", ans[i]);
}
int main() {
  solve();
  return 0;
}
