#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e4 + 7;
struct node {
  int l, r, id;
} Q[maxn];
int n, m;
int a[maxn], ans[maxn], R[maxn], b[maxn], c[maxn];
int f(int x) {
  if (x % 4 == 0) return x;
  if (x % 4 == 1) return 1;
  if (x % 4 == 2) return x + 1;
  if (x % 4 == 3) return 0;
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    b[i] = f(a[i] - 1);
    c[i] = f(a[i]);
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &Q[i].l, &Q[i].r);
  }
  for (int i = 1; i <= n; i++) {
    R[i - 1] = 0;
    for (int j = i; j <= n; j++) {
      int tmp;
      if (a[i] <= a[j])
        tmp = b[i] ^ c[j];
      else
        tmp = b[j] ^ c[i];
      R[j] = max(R[j - 1], tmp);
    }
    for (int j = 1; j <= m; j++) {
      if (Q[j].l <= i && Q[j].r >= i) ans[j] = max(ans[j], R[Q[j].r]);
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
