#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 5, M = 5e3 + 5;
int x[1000005], a[N], l[M], r[M], tmp[N], ans[M];
int main() {
  int n, m;
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= 1000000; i++) x[i] = x[i - 1] ^ i;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 1; i <= m; i++) scanf("%d %d", l + i, r + i);
  for (int i = 1; i <= n; i++) {
    int res = 0;
    for (int j = i; j <= n; j++) {
      if (a[i] <= a[j])
        res = max(res, x[a[i] - 1] ^ x[a[j]]);
      else
        res = max(res, x[a[j] - 1] ^ x[a[i]]);
      tmp[j] = res;
    }
    for (int j = 1; j <= m; j++)
      if (l[j] <= i && i <= r[j]) ans[j] = max(ans[j], tmp[r[j]]);
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
