#include <bits/stdc++.h>
using namespace std;
const int Max = 1e6 + 3;
int n, m, a[50005], g[Max], b[50005], ans[5005];
struct node {
  int l, r;
} q[5005];
int read() {
  int x, f = 1;
  char ch;
  while (!(isdigit(ch = getchar()))) ch == '-' ? f = -1 : f;
  x = ch - 48;
  while ((isdigit(ch = getchar()))) x = x * 10 + ch - 48;
  return f * x;
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= Max; i++) g[i] = i ^ g[i - 1];
  for (int i = 1; i <= n; i++) a[i] = read();
  for (int i = 1; i <= m; i++) q[i].l = read(), q[i].r = read();
  for (int i = 1; i <= n; i++) {
    int maxn = 0;
    for (int j = i; j <= n; j++) {
      if (a[i] >= a[j])
        maxn = max(maxn, g[a[j] - 1] ^ g[a[i]]);
      else
        maxn = max(maxn, g[a[i] - 1] ^ g[a[j]]);
      b[j] = maxn;
    }
    for (int j = 1; j <= m; j++)
      if (q[j].l <= i && i <= q[j].r) {
        ans[j] = max(ans[j], b[q[j].r]);
      }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
