#include <bits/stdc++.h>
using namespace std;
template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for (auto &v : vec) is >> v;
  return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  for (int i = 0; i < vec.size(); i++) {
    os << vec[i];
    if (i + 1 != vec.size()) os << " ";
  }
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const set<T> &st) {
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    os << *itr;
    auto titr = itr;
    if (++titr != st.end()) os << " ";
  }
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_set<T> &st) {
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    os << *itr;
    auto titr = itr;
    if (++titr != st.end()) os << " ";
  }
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const multiset<T> &st) {
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    os << *itr;
    auto titr = itr;
    if (++titr != st.end()) os << " ";
  }
  return os;
}
template <typename T>
ostream &operator<<(ostream &os, const unordered_multiset<T> &st) {
  for (auto itr = st.begin(); itr != st.end(); ++itr) {
    os << *itr;
    auto titr = itr;
    if (++titr != st.end()) os << " ";
  }
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p) {
  os << p.first << " " << p.second;
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const map<T1, T2> &mp) {
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    os << itr->first << ":" << itr->second;
    auto titr = itr;
    if (++titr != mp.end()) os << " ";
  }
  return os;
}
template <typename T1, typename T2>
ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp) {
  for (auto itr = mp.begin(); itr != mp.end(); ++itr) {
    os << itr->first << ":" << itr->second;
    auto titr = itr;
    if (++titr != mp.end()) os << " ";
  }
  return os;
}
using ll = long long int;
using P = pair<int, int>;
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
struct fast_io {
  fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);
  }
} fast_io_;
struct Node {
  int idx = 0, left = -1, right = -1;
  int cnt = 0;
  int mini = inf;
  int maxi = -1;
  Node() {}
  Node(int idx, int l, int r) : idx(idx), left(l), right(r) {}
};
struct Trie {
  int m = 19;
  vector<Node> v;
  Trie() { v.emplace_back(0, -1, -1); }
  Node &root() { return v[0]; }
  void insert(int x, int y) {
    int curr = 0;
    v[curr].mini = ::min(v[curr].mini, y);
    v[curr].maxi = ::max(v[curr].maxi, y);
    for (int i = m; i >= 0; i--) {
      bool right = ((x >> i) & 1);
      if (!right) {
        if (v[curr].left == -1) {
          v[curr].left = ((int)(v).size());
          v.emplace_back(v[curr].left, -1, -1);
        }
        curr = v[curr].left;
      } else {
        if (v[curr].right == -1) {
          v[curr].right = ((int)(v).size());
          v.emplace_back(v[curr].right, -1, -1);
        }
        curr = v[curr].right;
      }
      v[curr].mini = ::min(v[curr].mini, y);
      v[curr].maxi = ::max(v[curr].maxi, y);
    }
    v[curr].cnt++;
  }
  int max(int x, int y, bool big) {
    int curr = 0;
    int res = 0;
    for (int i = m; i >= 0; i--) {
      if (v[curr].left == -1 && v[curr].right == -1) {
        res ^= (x & ((1 << (i + 1)) - 1));
        return -1;
        break;
      }
      if (v[curr].left == -1) {
        res ^= ((x & (1 << i)) ^ (1 << (i)));
        if (big && v[v[curr].right].mini > y) return -1;
        if (!big && v[v[curr].right].maxi < y) return -1;
        curr = v[curr].right;
      } else if (v[curr].right == -1) {
        res ^= (x & (1 << i));
        if (big && v[v[curr].left].mini > y) return -1;
        if (!big && v[v[curr].left].maxi < y) return -1;
        curr = v[curr].left;
      } else {
        bool right = ((x >> i) & 1);
        bool rgo = true, lgo = true;
        if ((big && v[v[curr].right].mini > y) ||
            (!big && v[v[curr].right].maxi < y))
          rgo = false;
        if ((big && v[v[curr].left].mini > y) ||
            (!big && v[v[curr].left].maxi < y))
          lgo = false;
        if (!right) {
          if (!rgo) {
            if (lgo)
              curr = v[curr].left;
            else
              return -1;
          } else {
            res ^= (1 << i);
            curr = v[curr].right;
          }
        } else {
          if (!lgo) {
            if (rgo)
              curr = v[curr].right;
            else
              return -1;
          } else {
            res ^= (1 << i);
            curr = v[curr].left;
          }
        }
      }
    }
    return res;
  }
};
int xo[1000100];
const int b = 300;
int l[5010], r[5010];
vector<int> li[301];
int ans[5010];
int main(int argc, char const *argv[]) {
  int n, m;
  cin >> n >> m;
  xo[0] = 0;
  for (int i = (1); i < (1000001); ++i) xo[i] = xo[i - 1] ^ i;
  vector<int> a(n);
  cin >> a;
  for (int i = (0); i < (m); ++i) {
    cin >> l[i] >> r[i], l[i]--;
    li[l[i] / b].emplace_back(i);
  }
  for (int i = (0); i < (b); ++i) {
    sort((li[i]).begin(), (li[i]).end(), [&](int j, int k) {
      if (r[j] != r[k])
        return r[j] < r[k];
      else
        return l[j] < l[k];
    });
    Trie tr1, tr2;
    int rres = 0;
    int rnext = i * b + b;
    for (auto e : li[i]) {
      Trie t1, t2;
      int res = 0;
      for (; rnext < r[e]; rnext++) {
        tr1.insert(xo[a[rnext] - 1], a[rnext] - 1);
        tr2.insert(xo[a[rnext]], a[rnext]);
        rres = max(rres, tr1.max(xo[a[rnext]], a[rnext], true));
        rres = max(rres, tr2.max(xo[a[rnext] - 1], a[rnext], false));
      }
      for (int j = l[e]; j < min(i * b + b, r[e]); j++) {
        res = max(res, tr1.max(xo[a[j]], a[j], true));
        res = max(res, tr2.max(xo[a[j] - 1], a[j], false));
        t1.insert(xo[a[j] - 1], a[j] - 1);
        t2.insert(xo[a[j]], a[j]);
        res = max(res, t1.max(xo[a[j]], a[j], true));
        res = max(res, t2.max(xo[a[j] - 1], a[j], false));
      }
      ans[e] = max(res, rres);
    }
  }
  for (int i = (0); i < (m); ++i) cout << ans[i] << "\n";
  cout << flush;
  return 0;
}
