#include <bits/stdc++.h>
using namespace std;
const int A = 1e6 + 5;
const int N = 5e4 + 5;
const int M = 5005;
int dp[A], a[N], l[M], r[M], b[N], ans[M];
int32_t main() {
  for (int i = 1; i < A; i++) dp[i] = dp[i - 1] ^ i;
  int n, m;
  cin >> n >> m;
  for (int i = 1; i <= n; i++) scanf("%d", a + i);
  for (int i = 0; i < m; i++) scanf("%d%d", l + i, r + i);
  for (int i = 1; i <= n; i++) {
    b[i - 1] = 0;
    for (int j = i; j <= n; j++)
      b[j] = max(b[j - 1], a[i] < a[j] ? dp[a[j]] ^ dp[a[i] - 1]
                                       : dp[a[i]] ^ dp[a[j] - 1]);
    for (int j = 0; j < m; j++)
      if (l[j] <= i) ((ans[j]) = max((ans[j]), (b[r[j]])));
  }
  for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  return 0;
}
