#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') ch = getchar();
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  return x;
}
inline int Max(int x, int y) {
  if (x > y) return x;
  return y;
}
inline int Min(int x, int y) {
  if (x < y) return x;
  return y;
}
inline void write(int x) {
  if (x > 9) write(x / 10);
  putchar((x % 10) + '0');
}
const int MAXN = 5e4 + 10;
const int MAXM = 5e3 + 10;
int n, m;
int a[MAXN];
int l[MAXN], r[MAXN];
int f[MAXN];
int ans[MAXN];
int sum[1000010];
void init() {
  for (int i = 1; i <= 1e6 + 5; i++) sum[i] = sum[i - 1] ^ i;
}
int main() {
  init();
  n = read(), m = read();
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= m; i++) l[i] = read(), r[i] = read();
  for (int i = 1; i <= n; i++) {
    f[i] = a[i];
    for (int j = i + 1; j <= n; j++) {
      int Mx = Max(a[i], a[j]), Mn = Min(a[i], a[j]);
      f[j] = Max(f[j - 1], sum[Mx] ^ sum[Mn - 1]);
    }
    for (int j = 1; j <= m; j++)
      if (l[j] <= i && r[j] >= i) ans[j] = Max(ans[j], f[r[j]]);
  }
  for (int i = 1; i <= m; i++) write(ans[i]), puts("");
  return 0;
}
