#include <bits/stdc++.h>
using namespace std;
vector<long long> num;
long long record[1000000 + 5];
long long dp[50005], ans[50005];
int L[50005], R[50005];
int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  num.resize(n);
  for (int i = 0; i < n; i++) scanf("%I64d", &num[i]);
  int x, y;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    x--, y--;
    L[i] = x, R[i] = y;
  }
  record[1] = 1;
  for (int i = 2; i <= 1000000; i++) record[i] = i ^ record[i - 1];
  for (int i = 0; i < n; i++) {
    long long tmp = 0;
    for (int j = i; j < n; j++) {
      if (num[j] >= num[i])
        tmp = max(tmp, record[num[j]] ^ record[num[i] - 1]);
      else
        tmp = max(tmp, record[num[i]] ^ record[num[j] - 1]);
      dp[j] = tmp;
    }
    for (int j = 0; j < m; j++) {
      if (L[j] <= i && R[j] >= i) ans[j] = max(ans[j], dp[R[j]]);
    }
  }
  for (int i = 0; i < m; i++) printf("%I64d\n", ans[i]);
  return 0;
}
