#include <bits/stdc++.h>
using namespace std;
const int maxn = 50500;
const int maxm = 5050;
const int inf = 1000100;
struct Node {
  int l, r, id;
  void input(int idx) {
    id = idx;
    scanf("%d%d", &l, &r);
  }
  bool friend operator<(const Node &a, const Node &b) { return a.r < b.r; }
} p[maxm];
int n, m, a[maxn], sum[inf], ans[maxm];
int main() {
  for (int i = 1; i < inf; i++) sum[i] = sum[i - 1] ^ i;
  while (scanf("%d%d", &n, &m) != EOF) {
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int i = 0; i < m; i++) p[i].input(i);
    sort(p, p + m);
    for (int i = 1; i <= n; i++) {
      int r = i;
      int now = 0;
      for (int j = 0; j < m; j++) {
        if (p[j].r < i || i < p[j].l) continue;
        while (r <= p[j].r) {
          if (a[i] < a[r])
            now = max(now, sum[a[r]] ^ sum[a[i] - 1]);
          else
            now = max(now, sum[a[i]] ^ sum[a[r] - 1]);
          r++;
        }
        ans[p[j].id] = max(ans[p[j].id], now);
      }
    }
    for (int i = 0; i < m; i++) printf("%d\n", ans[i]);
  }
}
