#include <bits/stdc++.h>
using namespace std;
const int N = 1 << 16;
int n, q, a[N], l[N], r[N], dp[N], ans[N], g[N * 20];
int main() {
  for (int i = 1; i < N * 20; i++) g[i] = i ^ g[i - 1];
  scanf("%d%d", &n, &q);
  for (int i = 0; i < n; i++) scanf("%d", a + i);
  for (int i = 0; i < q; i++) scanf("%d%d", l + i, r + i);
  for (int i = 0; i < n; i++) {
    int c = 0;
    for (int j = i; j < n; j++)
      dp[j] = c = max(c, g[a[i]] ^ g[a[j]] ^ min(a[i], a[j]));
    for (int j = 0; j < q; j++)
      if (l[j] - 2 < i and i < r[j]) ans[j] = max(ans[j], dp[r[j] - 1]);
  }
  for (int i = 0; i < q; i++) printf("%d\n", ans[i]);
  return 0;
}
