#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];
inline int read() {
  int first = 0;
  while (1) {
    char ch = getchar();
    if (ch == ' ' || ch == '\n') break;
    first = first * 10 + ch - '0';
  }
  return first;
}
int bb[8];
inline void write(int ans) {
  if (!ans) {
    putchar('0');
    return;
  }
  int k = 0;
  while (ans) {
    bb[k] = char((ans % 10) + '0');
    ++k;
    ans /= 10;
  }
  for (int i = k - 1; i >= 0; --i) putchar(bb[i]);
  putchar('\n');
}
int main() {
  n = read();
  m = read();
  for (int i = 1; i <= 1000000; ++i) z[i] = z[i - 1] ^ i;
  for (int i = 1; i <= n; ++i) a[i] = read();
  for (int i = 1; i <= m; ++i) l[i] = read(), r[i] = read();
  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) write(ans[i]);
}
