#include <bits/stdc++.h>
using namespace std;
int y[1000005];
int main() {
  y[0] = 0;
  for (int i = 1; i <= 1000002; i++) y[i] = y[i - 1] ^ i;
  int n, m;
  while (scanf("%d %d", &n, &m) != EOF) {
    int a[50005], l[5005], r[5005];
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 1; i <= m; i++) scanf("%d %d", &l[i], &r[i]);
    int ans[5005];
    memset(ans, 0, sizeof(ans));
    for (int i = 1; i <= n; i++) {
      int qq[50005];
      for (int j = i; j <= n; j++) {
        int minn = min(a[i], a[j]);
        int maxx = max(a[i], a[j]);
        if (j == i)
          qq[j] = y[maxx] ^ y[minn - 1];
        else
          qq[j] = max(qq[j - 1], y[maxx] ^ y[minn - 1]);
      }
      for (int k = 1; k <= m; k++) {
        if (i >= l[k] && i <= r[k]) {
          ans[k] = max(ans[k], qq[r[k]]);
        }
      }
    }
    for (int i = 1; i <= m; i++) cout << ans[i] << endl;
  }
  return 0;
}
