#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 5;
int dp[N], sum[N], a[N / 10];
int n, q, ans[N / 100], l[N / 100], r[N / 100];
int main() {
  sum[0] = 0;
  for (int i = 1; i <= 1e6; i++) sum[i] = sum[i - 1] ^ i;
  while (~scanf("%d%d", &n, &q)) {
    memset(ans, 0, sizeof(ans));
    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++) {
      int c = 0;
      for (int j = i; j <= n; j++) {
        dp[j] = c = max(c, sum[a[i]] ^ sum[a[j]] ^ min(a[i], a[j]));
      }
      for (int j = 1; j <= q; j++)
        if (i >= l[j] && i <= r[j]) ans[j] = max(ans[j], dp[r[j]]);
    }
    for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  }
  return 0;
}
