#include <bits/stdc++.h>
using namespace std;
int n, m, Unit, Q_tot;
struct Trie {
  int l, r, size;
} t[50010 * 40];
struct Ask {
  int l, r, size, id;
} q[50010];
int A[50010], C[30], f[50010 * 20], Ans[50010], tot, root1, root2;
queue<int> Q;
stack<int> st;
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
int New_node() {
  if (!Q.empty()) {
    int now = Q.front();
    Q.pop();
    t[now].size = 0;
    t[now].l = t[now].r = 0;
    return now;
  } else {
    t[++tot].size = 0;
    t[tot].l = t[tot].r = 0;
    return tot;
  }
}
void Init() {
  while (!Q.empty()) Q.pop();
  tot = 0;
  root1 = New_node();
  root2 = New_node();
}
void Insert(int x, int k, int val) {
  int tmp;
  for (int i = 20; i >= 0; i--) {
    if (k & C[i]) {
      if (t[x].r)
        tmp = t[x].r;
      else {
        t[x].r = New_node();
        tmp = t[x].r;
      }
      if (t[tmp].size + val > 0)
        t[tmp].size += val;
      else {
        t[x].r = 0;
        Q.push(tmp);
      }
      x = tmp;
    } else {
      if (t[x].l)
        tmp = t[x].l;
      else {
        t[x].l = New_node();
        tmp = t[x].l;
      }
      if (t[tmp].size + val > 0)
        t[tmp].size += val;
      else {
        t[x].l = 0;
        Q.push(tmp);
      }
      x = tmp;
    }
  }
}
int Find1(int x, int k) {
  int Sum = 0;
  bool qqq = false;
  for (int i = 20; i >= 0; i--) {
    if (k & C[i]) {
      if (qqq) {
        if (t[x].l) {
          Sum += C[i];
          x = t[x].l;
        } else
          x = t[x].r;
      } else if (t[x].r)
        x = t[x].r;
      else
        return k;
    } else {
      if (t[x].r) {
        Sum += C[i];
        x = t[x].r;
        qqq = true;
      } else
        x = t[x].l;
    }
  }
  return Sum;
}
int Find2(int x, int k) {
  int Sum = 0;
  bool qqq = false;
  for (int i = 20; i >= 0; i--) {
    if (k & C[i]) {
      if (t[x].l) {
        Sum += C[i];
        x = t[x].l;
        qqq = true;
      } else
        x = t[x].r;
    } else {
      if (qqq) {
        if (t[x].r) {
          Sum += C[i];
          x = t[x].r;
        } else
          x = t[x].l;
      } else if (t[x].l)
        x = t[x].l;
      else
        return k;
    }
  }
  return Sum;
}
int Cmp(const Ask &a, const Ask &b) {
  int pd1 = (a.l - 1) / Unit + 1, pd2 = (b.l - 1) / Unit + 1;
  if (pd1 == pd2)
    return a.r < b.r;
  else
    return pd1 < pd2;
}
void Solve() {
  int L = 0, R = 0, ans = 0;
  for (int i = 1; i <= Q_tot; i++) {
    int qwer = (q[i].l - 1) / Unit + 1, Now_L = Unit * qwer;
    if (Now_L > L) {
      ans = 0;
      L = Now_L;
      R = Now_L - 1;
      Init();
    }
    while (R < q[i].r) {
      R++;
      Insert(root1, f[A[R] - 1], 1);
      Insert(root2, f[A[R]], 1);
      int tmp = max(Find1(root2, f[A[R] - 1]), Find2(root1, f[A[R]]));
      tmp = max(tmp, A[R]);
      ans = max(ans, tmp);
    }
    int haha = ans;
    for (int j = q[i].l; j < Now_L; j++) {
      st.push(A[j]);
      Insert(root1, f[A[j] - 1], 1);
      Insert(root2, f[A[j]], 1);
      int tmp = max(Find1(root2, f[A[j] - 1]), Find2(root1, f[A[j]]));
      tmp = max(tmp, A[j]);
      ans = max(ans, tmp);
    }
    while (!st.empty()) {
      int now = st.top();
      st.pop();
      Insert(root1, f[now - 1], -1);
      Insert(root2, f[now], -1);
    }
    Ans[q[i].id] = ans;
    ans = haha;
  }
}
int Str_work(int l, int r) {
  int ans = 0;
  Init();
  for (int i = l; i <= r; i++) {
    Insert(root1, f[A[i] - 1], 1);
    Insert(root2, f[A[i]], 1);
    int tmp = max(Find1(root2, f[A[i] - 1]), Find2(root1, f[A[i]]));
    tmp = max(tmp, A[i]);
    ans = max(ans, tmp);
  }
  return ans;
}
void Prepare() {
  f[0] = 0;
  for (int i = 1; i <= 1000000; i++) f[i] = f[i - 1] ^ i;
  C[0] = 1;
  for (int i = 1; i <= 29; i++) C[i] = C[i - 1] << 1;
}
int main() {
  Prepare();
  n = read();
  m = read();
  Unit = (int)sqrt((double)n + 1.0);
  for (int i = 1; i <= n; i++) A[i] = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    if (y - x <= Unit + 1)
      Ans[i] = Str_work(x, y);
    else {
      q[++Q_tot].l = x;
      q[Q_tot].r = y;
      q[Q_tot].id = i;
    }
  }
  sort(q + 1, q + Q_tot + 1, Cmp);
  Solve();
  for (int i = 1; i <= m; i++) printf("%d\n", Ans[i]);
  return 0;
}
