#include <bits/stdc++.h>
using namespace std;
template <class T>
inline T read() {
  char ch = ' ';
  T ret = (T)0;
  bool positive = 1;
  while (!(ch >= '0' && ch <= '9')) {
    if (ch == '-') positive ^= 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    ret = ret * ((T)10) + ((T)(ch - '0'));
    ch = getchar();
  }
  return positive ? ret : -ret;
}
const int N = 50010, M = 20, S = 1000010;
int XOR[S];
int n, m, arr[N], tmp[N];
int qx[N], qy[N], ans[N];
int main() {
  XOR[0] = 0;
  for (int i = 1; i < S; i++) XOR[i] = XOR[i - 1] ^ i;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &arr[i]);
  for (int i = 1; i <= m; i++) scanf("%d%d", &qx[i], &qy[i]);
  for (int i = 1; i <= n; i++) {
    tmp[i - 1] = 0;
    for (int j = i; j <= n; j++) {
      tmp[j] = XOR[arr[j]] ^ XOR[arr[i]] ^ min(arr[i], arr[j]);
      tmp[j] = max(tmp[j], tmp[j - 1]);
    }
    for (int j = 1; j <= m; j++)
      if (qx[j] <= i && i <= qy[j]) ans[j] = max(ans[j], tmp[qy[j]]);
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
