#include <bits/stdc++.h>
using namespace std;
const int maxv = 1000000 + 10;
const int maxn = 50000 + 10;
const int maxm = 5000 + 10;
int n, m;
int a[maxn], b[maxn], l[maxm], r[maxm], ans[maxm];
int f[maxv], g[maxn];
int main() {
  f[0] = 0;
  for (int i = 1; i < maxv; i++) f[i] = f[i - 1] ^ i;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    g[i] = f[a[i]];
  }
  for (int i = 1; i <= m; i++) scanf("%d%d", l + i, r + i);
  for (int i = 1; i <= n; i++) {
    b[i - 1] = 0;
    for (int j = i; j <= n; j++)
      b[j] = max(b[j - 1], g[i] ^ g[j] ^ (a[i] < a[j] ? a[i] : a[j]));
    for (int j = 1; j <= m; j++)
      if (l[j] <= i && i <= r[j]) ans[j] = max(ans[j], b[r[j]]);
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
