#include <bits/stdc++.h>
int f[1001001];
int a[610000];
int l[610000];
int r[610000];
int Max[600000];
int ans[600000];
int n, m;
int main() {
  for (int i = 1; i <= 1000000; i++) f[i] = f[i - 1] ^ i;
  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 maxs = 0;
    for (int j = i; j <= n; j++) {
      int tmp = f[a[j]] ^ f[a[i]];
      if (a[j] < a[i])
        tmp ^= a[j];
      else
        tmp ^= a[i];
      maxs = std::max(maxs, tmp);
      Max[j] = maxs;
    }
    for (int j = 1; j <= m; j++)
      if (l[j] <= i && i <= r[j]) ans[j] = std::max(ans[j], Max[r[j]]);
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
