#include <bits/stdc++.h>
using namespace std;
const int LAST = 1 << 20;
int RAIZ;
int n, Q;
int etzor[1000002];
int arr[50002];
struct _trie {
  struct ura {
    int uno, cero;
    int mayor;
  };
  ura tree[50002 * 20];
  int newNodo;
  void clear() {
    newNodo = 0;
    tree[newNodo].uno = tree[newNodo].cero = 0;
    tree[newNodo].mayor = -(1 << 30);
  }
  void insert(int x, int val) {
    int c = 0;
    for (int i = LAST; i; i >>= 1) {
      if (x & i) {
        if (!tree[c].uno) {
          tree[c].uno = ++newNodo;
          tree[newNodo].uno = tree[newNodo].cero = 0;
          tree[newNodo].mayor = -(1 << 30);
        }
        c = tree[c].uno;
      } else {
        if (!tree[c].cero) {
          tree[c].cero = ++newNodo;
          tree[newNodo].uno = tree[newNodo].cero = 0;
          tree[newNodo].mayor = -(1 << 30);
        }
        c = tree[c].cero;
      }
      tree[c].mayor = max(tree[c].mayor, val);
    }
  }
  int query(int x, int val) {
    int num = 0;
    int c = 0;
    for (int i = LAST; i; i >>= 1) {
      if (x & i) {
        if (tree[c].cero && val < tree[tree[c].cero].mayor) {
          c = tree[c].cero;
          num |= i;
        } else {
          c = tree[c].uno;
        }
      } else {
        if (tree[c].uno && val < tree[tree[c].uno].mayor) {
          c = tree[c].uno;
          num |= i;
        } else {
          c = tree[c].cero;
        }
      }
    }
    return num;
  }
};
_trie inis, fines;
_trie inis_aux, fines_aux;
priority_queue<int> nums;
int mayor;
int mayor_aux;
void add(int x) {
  inis.insert(etzor[x - 1], -(x - 1));
  mayor = max(mayor, inis.query(etzor[x], -x));
  fines.insert(etzor[x], x);
  mayor = max(mayor, fines.query(etzor[x - 1], x - 1));
}
void add_aux(int x) {
  inis_aux.insert(etzor[x - 1], -(x - 1));
  mayor_aux = max(mayor_aux, inis.query(etzor[x], -x));
  mayor_aux = max(mayor_aux, inis_aux.query(etzor[x], -x));
  fines_aux.insert(etzor[x], x);
  mayor_aux = max(mayor_aux, fines.query(etzor[x - 1], x - 1));
  mayor_aux = max(mayor_aux, fines_aux.query(etzor[x - 1], x - 1));
}
int resp[5002];
pair<pair<int, int>, int> querys[5002];
bool f(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  if (a.first.first / RAIZ == b.first.first / RAIZ)
    return a.first.second < b.first.second;
  return a.first.first / RAIZ < b.first.first / RAIZ;
}
void solve() {
  int donde = -1;
  int tope;
  int aux;
  for (int i = 1; i <= Q; i++) {
    if (donde != querys[i].first.first / RAIZ) {
      donde = querys[i].first.first / RAIZ;
      inis.clear();
      fines.clear();
      mayor = 0;
      aux = tope = (querys[i].first.first / RAIZ + 1) * RAIZ - 1;
    }
    while (tope < n && tope < querys[i].first.second) add(arr[++tope]);
    inis_aux.clear();
    fines_aux.clear();
    mayor_aux = mayor;
    for (int j = min(aux, querys[i].first.second); j >= querys[i].first.first;
         j--)
      add_aux(arr[j]);
    resp[querys[i].second] = mayor_aux;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  for (int i = 1; i <= 1000000; i++) etzor[i] = etzor[i - 1] ^ i;
  cin >> n >> Q;
  for (int i = 1; i <= n; i++) cin >> arr[i];
  RAIZ = sqrt(n);
  int a, b;
  int mayor;
  for (int i = 1; i <= Q; i++) {
    cin >> a >> b;
    querys[i].first.first = a;
    querys[i].first.second = b;
    querys[i].second = i;
  }
  sort(querys + 1, querys + Q + 1, f);
  solve();
  for (int i = 1; i <= Q; i++) cout << resp[i] << "\n";
  return 0;
}
