#include <bits/stdc++.h>
using namespace std;
int f[1000111], a[50111], res[50111], l[50111], r[50111], cur[50111],
    cache[50111];
int n, m;
int main() {
  f[0] = 0;
  for (int i = (1), _b = (1000 * 1000); i <= _b; ++i) f[i] = f[i - 1] ^ i;
  while (scanf("%d%d", &n, &m) == 2) {
    for (int i = 0, _a = (n); i < _a; ++i) {
      scanf("%d", a + i);
      cache[i] = f[a[i]];
    }
    for (int i = 0, _a = (m); i < _a; ++i) {
      res[i] = -1;
      scanf("%d %d", l + i, r + i);
      --l[i];
      --r[i];
    }
    for (int i = 0, _a = (n); i < _a; ++i) {
      cur[i] = a[i];
      int mx = a[i];
      for (int j = i + 1; j < n; ++j) {
        int t = cache[i] ^ cache[j] ^ (a[i] < a[j] ? a[i] : a[j]);
        if (t > mx) mx = t;
        cur[j] = mx;
      }
      for (int j = 0; j < m; ++j)
        if (l[j] <= i && i <= r[j]) res[j] = max(res[j], cur[r[j]]);
    }
    for (int i = 0, _a = (m); i < _a; ++i) printf("%d\n", res[i]);
  }
}
