#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
const int inf = 0x3f3f3f3f;
struct trie {
  int ch[50002 * 2 * 20][2], valid[50002 * 2 * 20];
  int size;
  void insert(int x, int y) {
    int root = 0;
    valid[root] = max(valid[root], y);
    for (int i = 20; i >= 0; i--) {
      int tmp = (x >> i) & 1;
      if (!ch[root][tmp]) {
        ++size;
        memset(ch[size], 0, sizeof(ch[size]));
        valid[size] = -inf;
        ch[root][tmp] = size;
      }
      root = ch[root][tmp];
      valid[root] = max(valid[root], y);
    }
  }
  int find(int x, int y) {
    int root = 0, ans = 0;
    if (valid[root] <= y) return 0;
    for (int i = 20; i >= 0; i--) {
      int tmp = ((x >> i) & 1) ^ 1;
      if (ch[root][tmp] && valid[ch[root][tmp]] > y)
        ans += 1 << i, root = ch[root][tmp];
      else
        root = ch[root][tmp ^ 1];
    }
    return ans;
  }
  void clear() {
    size = 0;
    valid[0] = -inf;
    ch[0][0] = ch[0][1] = 0;
  }
};
trie X, Y;
struct node {
  int x, y, id;
};
int n, m, gap;
int sum[2000006];
int a[maxn], ans[maxn];
node p[maxn];
bool cmp(const node& p1, const node& p2) {
  if (p1.x / gap != p2.x / gap) return p1.x / gap < p2.x / gap;
  return p1.y < p2.y;
}
void Work(int l, int r, int mx) {
  int now = mx + 1, cur = 0;
  X.clear(), Y.clear();
  for (int i = l; i <= r; i++) {
    int x = p[i].x, y = p[i].y, id = p[i].id;
    for (; now <= y; ++now) {
      int val = a[now];
      X.insert(sum[val], val);
      Y.insert(sum[val - 1], -(val - 1));
      cur = max(cur, X.find(sum[val - 1], val - 1));
      cur = max(cur, Y.find(sum[val], -val));
    }
    ans[id] = cur;
    for (int j = x; j <= min(y, mx); j++) {
      int val = a[j];
      ans[id] = max(ans[id], X.find(sum[val - 1], val - 1));
      ans[id] = max(ans[id], Y.find(sum[val], -val));
    }
  }
  for (int i = l; i <= r; i++) {
    X.clear(), Y.clear();
    int x = p[i].x, y = p[i].y, id = p[i].id;
    for (int j = x; j <= min(y, mx); j++) {
      int val = a[j];
      X.insert(sum[val], val);
      Y.insert(sum[val - 1], -(val - 1));
      ans[id] = max(ans[id], X.find(sum[val - 1], val - 1));
      ans[id] = max(ans[id], Y.find(sum[val], -val));
    }
  }
}
int main() {
  scanf("%d %d", &n, &m);
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1; i <= 1e6; i++) sum[i] = sum[i - 1] ^ i;
  for (int i = 1; i <= m; i++) {
    scanf("%d %d", &p[i].x, &p[i].y);
    p[i].id = i;
  }
  gap = (int)(sqrt(n * 1.0));
  sort(p + 1, p + 1 + m, cmp);
  for (int i = 1; i <= m; i++) {
    int tmp = i, mx = -1;
    while (tmp <= m && p[tmp].x / gap == p[i].x / gap)
      mx = max(mx, p[tmp].x), ++tmp;
    --tmp;
    Work(i, tmp, mx);
    i = tmp;
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
