#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 5;
const int mod = 1005;
int l[maxn];
int r[maxn];
int pre[maxn];
int ans[maxn];
int a[maxn];
int t[maxn];
int main() {
  for (int i = 1; i < maxn; i++) pre[i] = pre[i - 1] ^ i;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= m; i++) cin >> l[i] >> r[i];
  for (int i = 1; i <= n; i++) {
    int mx = 0;
    for (int j = i; j <= n; j++) {
      int cnt = pre[a[i]] ^ pre[a[j]];
      cnt ^= min(a[i], a[j]);
      mx = max(cnt, mx);
      t[j] = mx;
    }
    for (int j = 1; j <= m; j++)
      if (l[j] <= i && i <= r[j]) ans[j] = max(ans[j], t[r[j]]);
  }
  for (int i = 1; i <= m; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}
