#include <bits/stdc++.h>
const int maxn = 5 * (1e5) + 100;
using namespace std;
int a[maxn];
int b[1000000 + 50];
int f[1000000 + 50];
int g[1000000 + 50];
void deal() {
  f[1] = 1;
  int i;
  for (i = 2; i < 1000010; i++) {
    f[i] = f[i - 1] ^ i;
  }
}
struct gion {
  int from, to;
};
gion gs[maxn];
int best[maxn];
int main() {
  int m, n;
  deal();
  int i, j, k;
  while (~scanf("%d%d", &n, &m)) {
    for (i = 1; i < n + 1; i++) {
      cin >> a[i];
      g[i] = f[a[i]];
    }
    for (i = 0; i < m; i++) {
      long long l, r;
      cin >> l >> r;
      gs[i].from = l;
      gs[i].to = r;
      best[i] = -1;
    }
    for (i = 1; i < n + 1; i++) {
      int tmp = 0;
      for (j = i; j < n + 1; j++) {
        int cx = g[i] ^ g[j] ^ (a[i] > a[j] ? a[j] : a[i]);
        tmp = max(tmp, cx);
        b[j] = tmp;
      }
      for (k = 0; k < m; k++) {
        if (i >= gs[k].from && i <= gs[k].to) {
          best[k] = max(best[k], b[gs[k].to]);
        }
      }
    }
    for (i = 0; i < m; i++) cout << best[i] << endl;
  }
}
