#include <bits/stdc++.h>
using namespace std;
const int mod = (int)1e9 + 7;
const int maxn = (int)50055;
const int sz = 202;
const double eps = 1e-9;
struct query {
  int l, r, id;
  query() {}
  query(int l, int r, int id) : l(l), r(r), id(id) {}
  bool operator<(const query& tmp) const {
    if (l / sz != tmp.l / sz) return l / sz < tmp.l / sz;
    if (r != tmp.r) return r < tmp.r;
    return id < tmp.id;
  }
};
struct trie {
  int n, nxt[maxn * 17][2], par[maxn * 17], mx[maxn * 17], mn[maxn * 17];
  void init() {
    n = 0;
    nxt[n][0] = nxt[n][1] = -1;
    mx[n] = 0, mn[n] = mod;
    par[n] = -1;
  }
  void push(int b, int val) {
    int cur = 0;
    for (int i = 31 - 1; i >= 0; i--) {
      int x = (b >> i) & 1;
      if (nxt[cur][x] == -1) {
        nxt[cur][x] = ++n;
        nxt[n][0] = nxt[n][1] = -1;
        mx[n] = 0, mn[n] = mod;
        par[n] = cur;
      }
      cur = nxt[cur][x];
    }
    mn[cur] = min(mn[cur], val);
    mx[cur] = max(mx[cur], val);
    while (cur) {
      cur = par[cur];
      mn[cur] = min(mn[cur], val);
      mx[cur] = max(mx[cur], val);
    }
  }
  int go_min(int b, int c) {
    int cur = 0, res = 0;
    for (int i = 31 - 1; i >= 0; i--) {
      int x = (b >> i) & 1;
      if (nxt[cur][x ^ 1] != -1 && mn[nxt[cur][x ^ 1]] <= c) {
        res |= (1 << i);
        cur = nxt[cur][x ^ 1];
      } else {
        cur = nxt[cur][x];
        if (cur == -1 || mn[cur] > c) return -1;
      }
    }
    return res;
  }
  int go_max(int b, int c) {
    int cur = 0, res = 0;
    for (int i = 31 - 1; i >= 0; i--) {
      int x = (b >> i) & 1;
      if (nxt[cur][x ^ 1] != -1 && mx[nxt[cur][x ^ 1]] >= c) {
        res |= (1 << i);
        cur = nxt[cur][x ^ 1];
      } else {
        cur = nxt[cur][x];
        if (cur == -1 || mx[cur] < c) return -1;
      }
    }
    return res;
  }
};
trie T0, T1;
int n, m, a[maxn], f[maxn * 20], ans[maxn];
query q[maxn / 10];
vector<query> V;
void solve() {
  T0.init();
  T1.init();
  int cur = 0, mxL = 0;
  for (int i = 0; i < ((int)(V).size()); i++) cur = max(cur, V[i].l);
  mxL = cur;
  int res = 0;
  for (auto it : V) {
    while (cur < it.r) {
      cur++;
      T1.push(f[a[cur]], a[cur]);
      T0.push(f[a[cur] - 1], a[cur]);
      res = max(res, T0.go_min(f[a[cur]], a[cur]));
      res = max(res, T1.go_max(f[a[cur] - 1], a[cur]));
    }
    int tmp = 0;
    if (it.r >= mxL) {
      for (int i = it.l; i < mxL + 1; i++) {
        tmp = max(tmp, T1.go_max(f[a[i] - 1], a[i]));
        tmp = max(tmp, T0.go_min(f[a[i]], a[i]));
      }
    }
    ans[it.id] = max(tmp, res);
  }
  for (auto it : V) {
    T0.init();
    T1.init();
    res = 0;
    for (int i = it.l; i < min(it.r, mxL) + 1; i++) {
      T0.push(f[a[i] - 1], a[i]);
      T1.push(f[a[i]], a[i]);
      res = max(res, T0.go_min(f[a[i]], a[i]));
      res = max(res, T1.go_max(f[a[i] - 1], a[i]));
    }
    ans[it.id] = max(ans[it.id], res);
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  for (int i = 1; i < 1000001; i++) f[i] = f[i - 1] ^ i;
  cin >> n >> m;
  for (int i = 1; i < n + 1; i++) cin >> a[i];
  for (int i = 1; i < m + 1; i++) {
    int l, r;
    cin >> l >> r;
    q[i] = query(l, r, i);
  }
  sort(q + 1, q + 1 + m);
  for (int i = 1; i < m + 1; i++) {
    V.push_back(q[i]);
    if (i < m && q[i].l / sz != q[i + 1].l / sz) {
      solve();
      V.clear();
    }
  }
  solve();
  for (int i = 1; i < m + 1; i++) cout << ans[i] << '\n';
}
