#include <bits/stdc++.h>
using namespace std;
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &_p) {
  return os << "(" << _p.first << "," << _p.second << ")";
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &_V) {
  bool f = true;
  os << "[";
  for (auto v : _V) {
    os << (f ? "" : ",") << v;
    f = false;
  }
  return os << "]";
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &_S) {
  bool f = true;
  os << "(";
  for (auto s : _S) {
    os << (f ? "" : ",") << s;
    f = false;
  }
  return os << ")";
}
template <typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &_M) {
  return os << set<pair<T, U>>(_M.begin(), _M.end());
}
const signed long long INF = 1000000100;
const long double EPS = 1e-9;
const int MAXN = 50050;
const int MAXW = 1 << 21;
const int S = 1000;
int N, QS;
int A[MAXN];
int first[MAXN];
int second[MAXN];
int F[MAXW];
struct trie {
  vector<pair<int *, int>> S;
  int *P, *Q;
  int result;
  trie() : P(new int[MAXW]), Q(new int[MAXW]) { clear(); }
  void clear() {
    memset(P, 107, sizeof(int) * MAXW);
    memset(Q, -1, sizeof(int) * MAXW);
    result = 0;
  }
  void insert(int k, int t) {
    int v = 1;
    update(&P[v], min(P[v], t));
    update(&Q[v], max(Q[v], t));
    for (int(i) = (19); (i) >= (0); (i)--) {
      if (((1 << i) & k) != 0) {
        v = 2 * v + 1;
      } else {
        v = 2 * v;
      }
      update(&P[v], min(P[v], t));
      update(&Q[v], max(Q[v], t));
    }
  }
  int query(int k, int p, int q) {
    int v = 1;
    int r = 0;
    for (int(i) = (19); (i) >= (0); (i)--) {
      int e = (((1 << i) & k) != 0);
      if (!(q < P[2 * v + (!e)] or p > Q[2 * v + (!e)])) {
        v = 2 * v + (!e);
        r |= (1 << i);
      } else {
        v = 2 * v + e;
      }
    }
    return r;
  }
  void update_result(int k, int p, int q) {
    update(&result, max(result, query(k, p, q)));
  }
  void rollback() {
    while (!S.empty()) {
      *(S.back().first) = S.back().second;
      S.pop_back();
    }
  }
  void begin() { S.clear(); }
  void update(int *Z, int v) {
    S.push_back({Z, *Z});
    *Z = v;
  }
};
void read_data() {
  scanf("%d %d", &N, &QS);
  for (int(i) = (1); (i) <= (N); (i)++) scanf("%d", A + i);
  for (int(i) = (1); (i) <= (QS); (i)++) scanf("%d %d", first + i, second + i);
}
void insert(trie &T0, trie &T1, int i) {
  T0.insert(F[A[i]], A[i]);
  T1.insert(F[A[i] - 1], A[i]);
  T0.update_result(F[A[i] - 1], A[i], INF);
  T1.update_result(F[A[i]], 0, A[i]);
}
void solve() {
  map<int, vector<pair<int, int>>> M;
  map<pair<int, int>, int> R;
  for (int(i) = (1); (i) <= (QS); (i)++)
    M[first[i] / S].push_back(make_pair(first[i], second[i]));
  trie P, Q;
  for (auto &m : M) {
    vector<pair<int, int>> &queries = m.second;
    sort(queries.begin(), queries.end(),
         [](pair<int, int> a, pair<int, int> b) {
           return make_pair(a.second, a.first) < make_pair(b.second, b.first);
         });
    int l = -INF;
    for (auto q : queries) l = max(l, q.first);
    P.clear();
    Q.clear();
    int r = l - 1;
    for (auto q : queries)
      if (q.second - q.first <= S + 3) {
        P.begin();
        Q.begin();
        for (int(i) = (q.first); (i) <= (q.second); (i)++) insert(P, Q, i);
        R[q] = max(P.result, Q.result);
        P.rollback();
        Q.rollback();
      }
    for (auto q : queries)
      if (q.second - q.first > S + 3) {
        int temp_l = q.first;
        int new_r = q.second;
        for (int(i) = (r + 1); (i) <= (new_r); (i)++)
          if (q.first <= i and i <= q.second) insert(P, Q, i);
        P.begin();
        Q.begin();
        for (int(i) = (l - 1); (i) >= (temp_l); (i)--)
          if (q.first <= i and i <= q.second) insert(P, Q, i);
        R[q] = max(P.result, Q.result);
        P.rollback();
        Q.rollback();
        r = new_r;
      }
  }
  for (int(i) = (1); (i) <= (QS); (i)++)
    printf("%d\n", R[make_pair(first[i], second[i])]);
}
int main() {
  for (int(i) = (1); (i) < (MAXW); (i)++) F[i] = (F[i - 1] ^ i);
  read_data();
  solve();
}
