#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e4 + 5, maxm = 1e6 + 5;
struct node {
  int l, r;
} q[maxn];
int n, m, s[maxm], a[maxm], ans[maxm], f[maxm];
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 3) + (x << 1) + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void write(int x) {
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  if (x > 9) write(x / 10);
  putchar('0' + x % 10);
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= maxm - 5; i++) s[i] = s[i - 1] ^ i;
  for (int i = 1; i <= m; i++) q[i].l = read(), q[i].r = read();
  for (register int i = 1; i <= n; i++) {
    f[i] = a[i];
    for (register int j = i + 1; j <= n; j++)
      f[j] = max(f[j - 1], s[min(a[i], a[j]) - 1] ^ s[max(a[i], a[j])]);
    for (register int j = 1; j <= m; j++)
      if (i >= q[j].l && i <= q[j].r) ans[j] = max(ans[j], f[q[j].r]);
  }
  for (int i = 1; i <= m; i++) write(ans[i]), puts("");
  return 0;
}
