#include <bits/stdc++.h>
const int N = 50531;
using namespace std;
int ar[N];
int n, tests;
int MM[N];
int Xf(int x) {
  if (x % 4 == 3) return 0;
  if (x % 4 == 0) return x;
  if (x % 4 == 1) return 1;
  if (x % 4 == 2) return x + 1;
}
int memo_xor[1000031];
inline int f(int u, int v) {
  return memo_xor[min(u, v) - 1] ^ memo_xor[max(u, v)];
}
int L[N], R[N], res[N];
vector<int> queries[N];
int ans[N];
int main() {
  ios_base::sync_with_stdio(0);
  for (int i = 1; i <= 1000000; i++) {
    memo_xor[i] = (memo_xor[i - 1] ^ i);
  }
  cin >> n >> tests;
  for (int i = 0; i < n; i++) {
    cin >> ar[i];
  }
  for (int i = 1; i <= tests; i++) {
    cin >> L[i] >> R[i];
    --L[i];
    --R[i];
    queries[R[i]].push_back(i);
  }
  for (int i = 0; i < n; i++) {
    for (int j = i; j >= 0; --j) {
      res[j] = max(res[j], f(ar[i], ar[j]));
    }
    for (int j = 0; j < queries[i].size(); j++) {
      int id = queries[i][j];
      for (int q = L[id]; q <= R[id]; q++) {
        ans[id] = max(ans[id], res[q]);
      }
    }
  }
  for (int i = 1; i <= tests; i++) {
    cout << ans[i] << endl;
  }
  cin.get();
  cin.get();
  return 0;
}
