#include <bits/stdc++.h>
using namespace std;
const int N = 5e5 + 1, M = 5e3 + 1;
int n, m, a[N], l[M], r[M], d[N], ans[M];
int z[1000001];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= 1000000; ++i) z[i] = z[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) {
    d[i - 1] = 0;
    for (int j = i; j <= n; ++j) {
      if (a[i] < a[j])
        d[j] = max(d[j - 1], z[a[j]] ^ z[a[i] - 1]);
      else
        d[j] = max(d[j - 1], z[a[j] - 1] ^ z[a[i]]);
    }
    for (int j = 1; j <= m; ++j)
      if (i >= l[j]) ans[j] = max(ans[j], d[r[j]]);
  }
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
}
