#include <bits/stdc++.h>
using namespace std;
int n, m;
int a[50010];
int s[1000010];
int maxn;
int l[5010], r[5010], ans[5010];
int f[50010];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]), maxn = max(maxn, a[i]);
  for (int i = 1; i <= maxn; i++) s[i] = s[i - 1] ^ i;
  for (int i = 1; i <= m; i++) scanf("%d%d", &l[i], &r[i]);
  for (int i = 1; i <= n; i++) {
    f[i] = a[i];
    for (int j = i + 1; j <= n; j++)
      f[j] = max(f[j - 1], s[min(a[i], a[j]) - 1] ^ s[max(a[i], a[j])]);
    for (int j = 1; j <= m; j++)
      if (l[j] <= i && i <= r[j]) ans[j] = max(ans[j], f[r[j]]);
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
}
