#include <bits/stdc++.h>
using namespace std;
long long powmod(long long a, long long b, long long MOD) {
  long long res = 1;
  a %= MOD;
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
  }
  return res;
}
const int N = 5E4 + 5;
const int M = 5E3 + 5;
const int LEN = 1E6 + 5;
int sum[LEN];
int a[N];
int mx[N];
int be[N];
int en[N];
int g[N];
int res[M];
int main() {
  for (int i = 1; i < LEN; i++) {
    sum[i] = sum[i - 1] ^ i;
  }
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= n; i++) {
    scanf("%d", a + i);
    g[i] = sum[a[i]];
  }
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", be + i, en + i);
  }
  for (int i = 1; i <= n; i++) {
    int mxtemp = 0;
    for (int j = i; j <= n; j++) {
      int temp = g[i] ^ g[j] ^ (a[i] < a[j] ? a[i] : a[j]);
      mxtemp = max(mxtemp, temp);
      mx[j] = mxtemp;
    }
    for (int j = 1; j <= m; j++) {
      if (i >= be[j] && i <= en[j]) {
        res[j] = max(res[j], mx[en[j]]);
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    printf("%d\n", res[i]);
  }
  return 0;
}
