#include <bits/stdc++.h>
using namespace std;
int i, j, n, m, st[5005], dr[5005], dp[50005], rs[5005], X[1000005], a[50005],
    aux;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  for (i = 1; i <= 1e6; ++i) X[i] = X[i - 1] ^ i;
  cin >> n >> m;
  for (i = 1; i <= n; ++i) cin >> a[i];
  for (i = 1; i <= m; ++i) cin >> st[i] >> dr[i];
  for (i = 1; i <= n; ++i) {
    for (dp[i - 1] = 0, j = i; j <= n; ++j) {
      dp[j] = dp[j - 1];
      if (a[i] <= a[j]) dp[j] = max(dp[j], X[a[j]] ^ X[a[i] - 1]);
      if (a[i] >= a[j]) dp[j] = max(dp[j], X[a[i]] ^ X[a[j] - 1]);
    }
    for (j = 1; j <= m; ++j)
      if (st[j] <= i && dr[j] >= i) rs[j] = max(rs[j], dp[dr[j]]);
  }
  for (i = 1; i <= m; ++i) cout << rs[i] << '\n';
  return 0;
}
