#include <bits/stdc++.h>
using namespace std;
struct A {
  int l, r, id;
} q[1000005];
int cmp(A x, A y) { return x.l < y.l; }
int n, m, a[1000005], sum[1000005], f[1000005], ans[1000005];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= 1000000; i++) sum[i] = sum[i - 1] ^ i;
  for (int i = 1; i <= m; i++) scanf("%d%d", &q[i].l, &q[i].r), q[i].id = i;
  sort(q + 1, q + 1 + m, cmp);
  for (int i = 1; i <= n; i++) {
    f[i] = a[i];
    for (int j = i + 1; j <= n; j++)
      f[j] = max(f[j - 1], sum[max(a[i], a[j])] ^ sum[min(a[i], a[j]) - 1]);
    for (int j = 1; j <= m; j++)
      if (q[j].l <= i && q[j].r >= i)
        ans[q[j].id] = max(ans[q[j].id], f[q[j].r]);
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
