#include <bits/stdc++.h>
using namespace std;
const int INF = (int)2e9;
const long long INFL = (long long)9e18;
const int MAXINT = ((~0) ^ (1 << 31));
const long long MAXLL = ((~0) ^ ((long long)1 << 63));
template <class T>
inline T pow2(T a) {
  return a * a;
}
template <class T>
inline bool mineq(T& a, T b) {
  return (a > b) ? (a = b, true) : false;
}
template <class T>
inline bool maxeq(T& a, T b) {
  return (a < b) ? (a = b, true) : false;
}
const int maxn = 5e4 + 100;
const int maxk = 1e6 + 100;
int n, m;
int num[maxn], best[maxn], ans[maxn], x[maxk];
int l[maxn], r[maxn];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  for (int i = 1; i < (int)(maxk); i++) x[i] = x[i - 1] ^ i;
  cin >> n >> m;
  for (int i = 0; i < (int)(n); i++) cin >> num[i];
  for (int i = 0; i < (int)(m); i++) {
    cin >> l[i] >> r[i];
    l[i]--;
    r[i]--;
  }
  for (int i = 0; i < (int)(n); i++) {
    best[i] = num[i];
    for (int j = i + 1; j < (int)(n); j++)
      best[j] = max(best[j - 1], x[num[i]] ^ x[num[j]] ^
                                     (num[i] > num[j] ? num[j] : num[i]));
    for (int j = 0; j < (int)(m); j++)
      if (l[j] <= i && r[j] >= i) maxeq(ans[j], best[r[j]]);
  }
  for (int i = 0; i < (int)(m); i++) cout << ans[i] << endl;
}
