#include <bits/stdc++.h>
using namespace std;
int quick_pow(int a, int b, int MOD) {
  a %= MOD;
  int res = 1;
  while (b) {
    if (b & 1) res = (res * a) % MOD;
    b /= 2;
    a = (a * a) % MOD;
  }
  return res;
}
const int maxn = 50000 + 10;
int a[maxn], b[maxn], res[maxn], x[maxn], y[maxn], sum[1000005], f[1000005];
int main() {
  int i, j, n, m;
  sum[0] = 0;
  for (i = 1; i <= 1000000; i++) sum[i] = (sum[i - 1] ^ i);
  while (scanf("%d%d", &n, &m) != EOF) {
    for (i = 1; i <= n; i++) {
      scanf("%d", &a[i]);
      f[i] = sum[a[i]];
    }
    for (i = 1; i <= m; i++) {
      scanf("%d%d", &x[i], &y[i]);
      res[i] = -1;
    }
    for (i = 1; i <= n; i++) {
      b[i - 1] = 0;
      for (j = i; j <= n; j++) {
        b[j] = max(b[j - 1], f[i] ^ f[j] ^ (a[i] < a[j] ? a[i] : a[j]));
      }
      for (j = 1; j <= m; j++) {
        if (x[j] <= i && y[j] >= i) {
          res[j] = max(res[j], b[y[j]]);
        }
      }
    }
    for (i = 1; i <= m; i++) printf("%d\n", res[i]);
  }
  return 0;
}
