#include <bits/stdc++.h>
using namespace std;
const int N = 5e4 + 5, M = 5e3 + 5, P = 1e9 + 7;
int n, q, f[(1 << 20) + 5], a[N], l[N], r[N], ma[N], ans[N];
int main() {
  for (int i = (1); i <= (1 << 20); i++) f[i] = f[i - 1] ^ i;
  cin >> n >> q;
  for (int i = (1); i <= (n); i++) scanf("%d", &a[i]);
  for (int i = (1); i <= (q); i++) scanf("%d%d", &l[i], &r[i]);
  for (int i = (1); i <= (n); i++) {
    ma[i - 1] = 0;
    for (int j = (i); j <= (n); j++)
      ma[j] = max(ma[j - 1], f[a[i]] ^ f[a[j]] ^ min(a[i], a[j]));
    for (int j = (1); j <= (q); j++)
      if (l[j] <= i) ans[j] = max(ans[j], ma[r[j]]);
  }
  for (int i = (1); i <= (q); i++) printf("%d\n", ans[i]);
  return 0;
}
