#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e6 + 3;
int f[MAX], a[MAX], l[MAX], r[MAX], dp[MAX], ans[MAX];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  for (int i = 1; i < MAX; i++) f[i] = f[i - 1] ^ i;
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < m; i++) cin >> l[i] >> r[i], l[i]--, r[i]--;
  for (int i = 0; i < n; i++) {
    int ma = 0;
    for (int j = i; j < n; j++) {
      if (a[j] < a[i])
        ma = max(ma, f[a[j] - 1] ^ f[a[i]]);
      else
        ma = max(ma, f[a[i] - 1] ^ f[a[j]]);
      dp[j] = ma;
    }
    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++) cout << ans[i] << '\n';
}
