#include <bits/stdc++.h>
using namespace std;
template <typename T1, typename T2>
istream& operator>>(istream& in, pair<T1, T2>& a) {
  in >> a.first >> a.second;
  return in;
}
template <typename T1, typename T2>
ostream& operator<<(ostream& out, pair<T1, T2> a) {
  out << a.first << " " << a.second;
  return out;
}
template <typename T, typename T1>
T maxs(T& a, T1 b) {
  if (b > a) a = b;
  return a;
}
template <typename T, typename T1>
T mins(T& a, T1 b) {
  if (b < a) a = b;
  return a;
}
long long pre[1000005];
long long ans[5005];
long long a[50005];
long long b[50005];
long long dp[50005];
vector<pair<long long, long long> > q;
long long solve() {
  long long n, m;
  cin >> n >> m;
  for (long long i = 0; i < n; i++) cin >> a[i + 1];
  for (long long i = 1; i <= 1000000; i++) pre[i] = pre[i - 1] ^ i;
  for (long long i = 1; i < n + 1; i++) b[i] = pre[a[i]];
  q.resize(m);
  for (long long i = 0; i < m; i++) cin >> q[i];
  for (long long i = 1; i <= n; i++) {
    long long mx = 0;
    for (long long j = i; j <= n; j++) {
      long long val = b[j] ^ b[i];
      if (a[i] > a[j])
        val ^= a[j];
      else
        val ^= a[i];
      maxs(mx, val);
      dp[j] = mx;
    }
    for (long long j = 0; j < m; j++) {
      if (q[j].first <= i && i <= q[j].second) maxs(ans[j], dp[q[j].second]);
    }
  }
  for (long long i = 0; i < m; i++) cout << ans[i] << "\n";
  return 0;
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  long long t = 1;
  while (t--) {
    solve();
  }
  return 0;
}
