#include <bits/stdc++.h>
using namespace std;
int const M = 1e6 + 13;
int const SZ = 350;
int const B = 20;
int const INF = 1e9 + 13;
int const N = 5e4 + 13;
int n, m, a[N];
int finc[M], fexc[M];
int ans[N];
vector<int> q[N];
int l[N], r[N];
bool bit(int mask, int id) { return (mask & (1 << id)); }
void remax(int &a, int b) { a = max(a, b); }
void remin(int &a, int b) { a = min(a, b); }
struct Trie {
  Trie *z, *o;
  int maxi, mini;
  Trie() {
    maxi = -INF;
    mini = INF;
    z = o = NULL;
  };
  int getMax(Trie *v) {
    if (!v) return -INF;
    return v->maxi;
  }
  int getMin(Trie *v) {
    if (!v) return INF;
    return v->mini;
  }
  void recalc() {
    mini = INF;
    maxi = -INF;
    mini = min(mini, min(getMin(z), getMin(o)));
    maxi = max(maxi, max(getMax(z), getMax(o)));
  }
  void push(int mask, int bid, int val) {
    if (bid == 0) {
      remin(mini, val);
      remax(maxi, val);
      return;
    }
    if (bit(mask, bid - 1)) {
      if (!o) o = new Trie();
      o->push(mask, bid - 1, val);
    } else {
      if (!z) z = new Trie();
      z->push(mask, bid - 1, val);
    }
    recalc();
  }
  int ansLeq(int mask, int bid, int val) {
    if (bid == 0) return 0;
    if (bit(mask, bid - 1)) {
      if (getMin(z) <= val)
        return ((1 << (bid - 1)) ^ z->ansLeq(mask, bid - 1, val));
      if (getMin(o) <= val) return o->ansLeq(mask, bid - 1, val);
      return 0;
    } else {
      if (getMin(o) <= val)
        return ((1 << (bid - 1)) ^ o->ansLeq(mask, bid - 1, val));
      if (getMin(z) <= val) return z->ansLeq(mask, bid - 1, val);
      return 0;
    }
  }
  int ansGeq(int mask, int bid, int val) {
    if (bid == 0) return 0;
    if (bit(mask, bid - 1)) {
      if (getMax(z) >= val)
        return ((1 << (bid - 1)) ^ z->ansGeq(mask, bid - 1, val));
      if (getMax(o) >= val) return o->ansGeq(mask, bid - 1, val);
      return 0;
    } else {
      if (getMax(o) >= val)
        return ((1 << (bid - 1)) ^ o->ansGeq(mask, bid - 1, val));
      if (getMax(z) >= val) return z->ansGeq(mask, bid - 1, val);
      return 0;
    }
  }
  void clear() {
    if (o) o->clear();
    if (z) z->clear();
    mini = INF;
    maxi = -INF;
  }
};
Trie tinc, texc;
bool cmpq(int i, int j) { return r[i] < r[j]; }
int answerLine(int l, int r) {
  int ret = 0;
  for (int i = l; i <= r; ++i) {
    int vinc = texc.ansLeq(finc[a[i]], B, a[i]);
    int vexc = tinc.ansGeq(fexc[a[i]], B, a[i]);
    ret = max(ret, max(vinc, vexc));
  }
  return ret;
}
int pushLine(int l, int r) {
  for (int i = l; i <= r; ++i) {
    tinc.push(finc[a[i]], B, a[i]);
    texc.push(fexc[a[i]], B, a[i]);
  }
  return answerLine(l, r);
}
int dp[SZ];
void buildDp(int maxl) {
  for (int i = 0; i < SZ; ++i) dp[i] = 0;
  for (int i = 1; i < min(SZ, maxl + 1); ++i) {
    dp[i] = dp[i - 1];
    for (int j = 0; j < i; ++j) {
      int cur;
      int v1 = a[maxl - i];
      int v2 = a[maxl - j];
      if (v1 > v2) swap(v1, v2);
      dp[i] = max(dp[i], (finc[v2] ^ fexc[v1]));
    }
  }
}
void solve(vector<int> &q) {
  tinc.clear();
  texc.clear();
  int maxl = -1, minr = INF;
  for (int i = 0; i < q.size(); ++i)
    maxl = max(maxl, l[q[i]]), minr = min(minr, r[q[i]]);
  buildDp(maxl);
  int ansr = pushLine(maxl, minr);
  for (int i = 0; i < q.size(); ++i) {
    ansr = max(ansr, pushLine(minr + 1, r[q[i]]));
    minr = r[q[i]];
    int lans = dp[maxl - l[q[i]]];
    lans = max(lans, answerLine(l[q[i]], maxl));
    ans[q[i]] = max(lans, ansr);
  }
}
int solveSmall(int l, int r) {
  tinc.clear();
  texc.clear();
  return pushLine(l, r);
}
void solve() {
  for (int i = 1; i < M; ++i)
    finc[i] = (i ^ finc[i - 1]), fexc[i] = finc[i - 1];
  scanf("%d %d", &n, &m);
  for (int i = 0; i < n; ++i) scanf("%d", &a[i]);
  for (int i = 0; i < m; ++i) {
    scanf("%d %d", &l[i], &r[i]);
    --l[i];
    --r[i];
    if (r[i] / SZ == l[i] / SZ) {
      ans[i] = solveSmall(l[i], r[i]);
    } else {
      q[l[i] / SZ].push_back(i);
    }
  }
  for (int i = 0; i < N; ++i)
    if (q[i].size() > 0) {
      sort(q[i].begin(), q[i].end(), cmpq);
      solve(q[i]);
    }
  for (int i = 0; i < m; ++i) printf("%d\n", ans[i]);
}
int main() {
  solve();
  return 0;
}
