#include <bits/stdc++.h>
using namespace std;
const int MAX = 1000001;
const int N = 51234;
const int M = N * 25;
int n, m, S;
int a[N], ans[N];
int prefix[1123456];
struct Query {
  int left, right, id;
  Query(int left, int right, int id) : left(left), right(right), id(id) {}
  bool operator<(const Query &A) const { return right < A.right; }
};
vector<Query> q[505];
class Tire {
 public:
  Tire() { clear(); }
  void clear() {
    m = 0;
    child[0][0] = child[0][1] = a[0] = 0;
  }
  void append(int u, int v) {
    int t = 0;
    for (int i = 20; i >= 0; --i) {
      int side = u >> i & 1;
      if (!child[t][side]) {
        child[t][side] = ++m;
        child[m][0] = child[m][1] = a[m] = 0;
      }
      t = child[t][side];
      a[t] = max(a[t], v);
    }
  }
  int getMax(int u, int v) {
    int t = 0, ans = 0;
    for (int i = 20; i >= 0; --i) {
      int side = (u >> i & 1) ^ 1;
      if (child[t][side] > 0 && v <= a[child[t][side]]) {
        t = child[t][side];
        ans += 1 << i;
      } else
        t = child[t][side ^ 1];
    }
    return ans;
  }

 private:
  int m;
  int a[M], child[M][2];
} tire[2], tmp[2];
int getAns(int l, int r) {
  for (int t = 0; t < 2; ++t) tmp[t].clear();
  int ans = 0;
  for (int j = l; j < r; ++j) {
    tmp[0].append(prefix[a[j]], a[j]);
    tmp[1].append(prefix[a[j] - 1], MAX - a[j]);
    int res = max(tmp[0].getMax(prefix[a[j] - 1], a[j]),
                  tmp[1].getMax(prefix[a[j]], MAX - a[j]));
    ans = max(ans, res);
  }
  return ans;
}
int main() {
  for (int i = 0; i < MAX; ++i) prefix[i + 1] = prefix[i] ^ (i + 1);
  scanf("%d%d", &n, &m);
  S = min(n, 130);
  S = n / (n / S);
  for (int i = 0; i < n; ++i) scanf("%d", a + i);
  for (int i = 0; i < m; ++i) {
    int x, y;
    scanf("%d%d", &x, &y), --x;
    int block = x / (n / S);
    int st = n / S * (block + 1);
    ans[i] = getAns(x, min(st, y));
    if (st < y) q[block].push_back(Query(x, y - 1, i));
  }
  for (int i = 0; i < S; ++i) {
    for (int t = 0; t < 2; ++t) tire[t].clear();
    int k = 0;
    int res = 0;
    int st = n / S * (i + 1);
    sort(q[i].begin(), q[i].end());
    for (int j = st; j < n; ++j) {
      tire[0].append(prefix[a[j]], a[j]);
      tire[1].append(prefix[a[j] - 1], MAX - a[j]);
      res = max(res, max(tire[0].getMax(prefix[a[j] - 1], a[j]),
                         tire[1].getMax(prefix[a[j]], MAX - a[j])));
      while (k < q[i].size() && j == q[i][k].right) {
        ans[q[i][k].id] = max(ans[q[i][k].id], res);
        for (int l = q[i][k].left; l < st; ++l)
          ans[q[i][k].id] = max(ans[q[i][k].id],
                                max(tire[0].getMax(prefix[a[l] - 1], a[l]),
                                    tire[1].getMax(prefix[a[l]], MAX - a[l])));
        ++k;
      }
    }
  }
  for (int i = 0; i < m; ++i) printf("%d\n", ans[i]);
  return 0;
}
