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