#include <bits/stdc++.h>
using namespace std;
int n, m;
int pref[1 << 20];
int a[50013], b[50013];
int dp[50013];
int l[5013], r[5013];
int ans[5013];
int main() {
  pref[0] = 0;
  for (int i = 1; i < (1 << 20); i++) pref[i] = pref[i - 1] ^ i;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    b[i] = pref[a[i]];
  }
  for (int i = 0; i < m; i++) scanf("%d%d", &l[i], &r[i]);
  for (int i = 1; i <= n; i++) {
    dp[i] = a[i];
    for (int j = i + 1; j <= n; j++) {
      dp[j] = max(dp[j - 1], b[i] ^ b[j] ^ min(a[i], a[j]));
    }
    for (int j = 0; j < m; j++) {
      if (l[j] <= i && i <= r[j]) ans[j] = max(ans[j], dp[r[j]]);
    }
  }
  for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  return 0;
}
