#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void amin(T &a, const T &b) {
  if (b < a) a = b;
}
template <class T>
inline void amax(T &a, const T &b) {
  if (a < b) a = b;
}
int F_(int x) {
  switch (x & 3) {
    case 0:
      return x;
    case 1:
      return 1;
    case 2:
      return x ^ 1;
    case 3:
      return 0;
    default:
      assert(false);
  }
}
int F(int x, int y) { return F_(x - 1) ^ F_(y); }
struct Query {
  int l, r, i;
  bool operator<(const Query &y) const { return r < y.r; }
};
int N, M;
int A[50011];
Query P[5011];
int R[50011], L[50011];
int ma[50011];
int ans[5011];
int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0, i_len = (N); i < i_len; ++i) scanf("%d", A + i);
  for (int i = 0, i_len = (M); i < i_len; ++i) {
    scanf("%d%d", &P[i].l, &P[i].r);
    P[i].l--;
    P[i].r--;
    P[i].i = i;
  }
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    R[i] = F_(A[i]);
    L[i] = F_(A[i] - 1);
  }
  sort(P, P + M);
  int k = 0;
  for (int i = 0, i_len = (N); i < i_len; ++i) {
    for (int j = 0, j_len = (i + 1); j < j_len; ++j) {
      amax(ma[j], (A[j] <= A[i]) ? L[j] ^ R[i] : L[i] ^ R[j]);
    }
    while (k < M && P[k].r <= i) {
      for (int j = P[k].l; j <= P[k].r; j++) {
        amax(ans[P[k].i], ma[j]);
      }
      k++;
    }
  }
  for (int i = 0, i_len = (M); i < i_len; ++i) printf("%d\n", ans[i]);
  return 0;
}
