#include <bits/stdc++.h>
using namespace std;
int N, M;
int A[50050], X[50500];
int L[50050], R[50500];
int XX[1010101];
int ma[50505];
int ret[50505];
signed long long xorxor(signed long long val) {
  int i;
  signed long long ret = ((val + 1) / 2) % 2;
  for (i = 0; i <= 29; i++)
    if ((val >> i) % 2) ret |= (1 ^ (val % 2)) << i;
  return ret;
}
void solve() {
  int i, j, k, l, r, x, y;
  string s;
  for (i = 1; i <= 1000000; i++) XX[i] = XX[i - 1] ^ i;
  cin >> N >> M;
  for (i = 0; i < (N); i++) cin >> A[i], X[i] = XX[A[i]];
  for (i = 0; i < (M); i++) cin >> L[i] >> R[i], L[i]--, R[i]--;
  for (x = 0; x < (N); x++) {
    ma[x - 1] = 0;
    for (y = x; y < N; y++)
      ma[y] = max(ma[y - 1], X[x] ^ X[y] ^ ((A[x] > A[y]) ? A[y] : A[x]));
    for (i = 0; i < (M); i++)
      if (L[i] <= x) ret[i] = max(ret[i], ma[R[i]]);
  }
  for (i = 0; i < (M); i++) cout << ret[i] << endl;
}
int main(int argc, char** argv) {
  string s;
  int i;
  if (argc == 1) ios::sync_with_stdio(false);
  for (i = 0; i < (argc - 1); i++) s += argv[i + 1], s += '\n';
  for (i = 0; i < (s.size()); i++) ungetc(s[s.size() - 1 - i], stdin);
  solve();
  return 0;
}
