#include <bits/stdc++.h>
using namespace std;
const int inf = (int)1e9;
const double eps = (double)1e-8;
const int mod = (int)1000000007;
const int maxn = (int)5 * 1e4 + 5;
int n, m, a[maxn];
int d[maxn], o[maxn], l[maxn], r[maxn];
int z[1000006];
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = (1); i <= (n); i++) {
    cin >> a[i];
  }
  z[0] = 0;
  for (int i = (1); i <= (1e6); i++) {
    z[i] = z[i - 1] ^ i;
  }
  for (int i = (1); i <= (m); i++) {
    cin >> l[i] >> r[i];
    o[i] = 0;
  }
  for (int i = (1); i <= (n); i++) {
    d[i - 1] = 0;
    for (int j = (i); j <= (n); j++) {
      d[j] = max(d[j - 1], z[max(a[i], a[j])] ^ z[min(a[i], a[j]) - 1]);
    }
    for (int j = (1); j <= (m); j++) {
      if (l[j] <= i) o[j] = max(o[j], d[r[j]]);
    }
  }
  for (int i = (1); i <= (m); i++) {
    cout << o[i] << "\n";
  }
  return 0;
}
