#include <bits/stdc++.h>
using namespace std;
int n;
int m;
int a[50010];
int sum[1000010];
int l[5010];
int r[5010];
int f[50010];
int ans[5010];
int main() {
  for (int i = 1; i <= 1000010; i++) {
    sum[i] = sum[i - 1] ^ i;
  }
  cin >> n >> m;
  for (int i = 1; i <= n; i++) {
    cin >> a[i];
  }
  for (int i = 1; i <= m; i++) {
    cin >> l[i] >> r[i];
  }
  for (int i = 1; i <= n; i++) {
    f[i] = a[i];
    for (int j = i + 1; j <= n; j++) {
      f[j] = max(f[j - 1], sum[min(a[i], a[j]) - 1] ^ sum[max(a[i], a[j])]);
    }
    for (int j = 1; j <= m; j++) {
      if (i >= l[j] && i <= r[j]) {
        ans[j] = max(ans[j], f[r[j]]);
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    cout << ans[i] << endl;
  }
  return 0;
}
