#include <bits/stdc++.h>
using namespace std;
char _;
const int maxN = 50 * 1000 + 5;
const int mod = 1000 * 1000 * 1000 + 7;
const int base = 701;
const int SQ = 600;
const int maxL = 20;
int l[maxN], r[maxN];
int g(int t) {
  if (t % 4 == 0) return t;
  if (t % 4 == 1) return 1;
  if (t % 4 == 2) return t + 1;
  return 0;
}
int bb[maxN], ans[maxN];
int a[maxN];
int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> l[i] >> r[i], l[i]--, r[i]--;
  for (int i = 0; i < n; i++) {
    int mx = 0;
    for (int j = i; j < n; j++) {
      int gg = g(a[i]) ^ g(a[j]) ^ min(a[i], a[j]);
      mx = max(mx, gg);
      bb[j] = mx;
    }
    for (int j = 0; j < m; j++)
      if (l[j] <= i && i <= r[j]) ans[j] = max(ans[j], bb[r[j]]);
  }
  for (int i = 0; i < m; i++) cout << ans[i] << endl;
  return 0;
}
