#include <bits/stdc++.h>
using namespace std;
const int MAXNODE = 50000 * 2 * 25 + 11;
const int MAXH = 20;
const int MAXN = 51111;
const int MAXQ = 5555;
const int INF = 1e9;
int a[MAXN], ans[MAXQ], n, Q, s;
struct Query {
  int l, r, id;
} q[MAXQ];
inline bool cmp(const Query &p, const Query &q) {
  if (p.l / s == q.l / s)
    return p.r < q.r;
  else
    return p.l / s < q.l / s;
}
struct Trie {
  int size[MAXNODE], value[MAXNODE], c[MAXNODE][2], cnt, rt;
  inline int getnode() {
    ++cnt;
    value[cnt] = -INF;
    size[cnt] = c[cnt][0] = c[cnt][1] = 0;
    return cnt;
  }
  inline void clear() {
    cnt = 0;
    rt = getnode();
  }
  inline void addnumber(int x, int val) {
    int u = rt;
    for (int h = MAXH; h >= 0; --h) {
      size[u]++;
      value[u] = max(value[u], val);
      int tx = (x >> h) & 1;
      if (!c[u][tx]) c[u][tx] = getnode();
      u = c[u][tx];
    }
    size[u]++;
    value[u] = max(value[u], val);
  }
  inline int query(int u, int d, int x, int val) {
    if (val > value[u] || !c[u][0] && !c[u][1] && d >= 0) return -INF;
    if (d < 0) return 0;
    int tx = ((x >> d) & 1) ^ 1;
    if (c[u][tx] && value[c[u][tx]] >= val)
      return (1 << d) + query(c[u][tx], d - 1, x, val);
    else
      return query(c[u][tx ^ 1], d - 1, x, val);
  }
  inline void print(int u) {
    if (u == rt) puts("--------------");
    printf("%d %d %d %d %d\n", u, c[u][0], c[u][1], size[u], value[u]);
    if (c[u][0]) print(c[u][0]);
    if (c[u][1]) print(c[u][1]);
  }
} A, B;
inline int getsum(int n) {
  if (n % 4 == 0) return n;
  if (n % 4 == 1) return 1;
  if (n % 4 == 2) return n + 1;
  return 0;
}
inline void solve(int l, int r, int mxl) {
  for (int i = l; i <= r; ++i) {
    A.clear();
    B.clear();
    for (int j = q[i].l; j <= q[i].r && j <= mxl; ++j) {
      A.addnumber(getsum(a[j] - 1), -a[j]);
      B.addnumber(getsum(a[j]), a[j]);
      ans[q[i].id] =
          max(ans[q[i].id], A.query(A.rt, MAXH, getsum(a[j]), -a[j]));
      ans[q[i].id] =
          max(ans[q[i].id], B.query(B.rt, MAXH, getsum(a[j] - 1), a[j]));
    }
  }
  A.clear();
  B.clear();
  int lastr = mxl, nowans = -INF;
  for (int i = l; i <= r; ++i) {
    for (int j = lastr + 1; j <= q[i].r; ++j) {
      A.addnumber(getsum(a[j] - 1), -a[j]);
      B.addnumber(getsum(a[j]), a[j]);
      nowans = max(nowans, A.query(A.rt, MAXH, getsum(a[j]), -a[j]));
      nowans = max(nowans, B.query(B.rt, MAXH, getsum(a[j] - 1), a[j]));
    }
    ans[q[i].id] = max(ans[q[i].id], nowans);
    lastr = max(lastr, q[i].r);
    for (int j = q[i].l; j <= q[i].r && j <= mxl; ++j) {
      ans[q[i].id] =
          max(ans[q[i].id], A.query(A.rt, MAXH, getsum(a[j]), -a[j]));
      ans[q[i].id] =
          max(ans[q[i].id], B.query(B.rt, MAXH, getsum(a[j] - 1), a[j]));
    }
  }
}
int main() {
  scanf("%d%d", &n, &Q);
  for (int i = 1; i <= n; ++i) scanf("%d", &a[i]);
  for (int i = 1; i <= Q; ++i) {
    scanf("%d%d", &q[i].l, &q[i].r);
    q[i].id = i;
    ans[i] = -INF;
  }
  s = sqrt(n);
  sort(q + 1, q + Q + 1, cmp);
  int i = 1;
  while (i <= Q) {
    int j = i, mx = q[i].l;
    while (j < Q && q[j + 1].l / s == q[i].l / s) mx = max(mx, q[++j].l);
    solve(i, j, mx);
    i = j + 1;
  }
  for (int i = 1; i <= Q; ++i) printf("%d\n", ans[i]);
}
