#include <bits/stdc++.h>
using namespace std;
int f[1000010], n, m, a[50010], dp[50010], ans[5010];
vector<pair<int, int> > v[50010];
int main() {
  scanf("%d%d", &n, &m);
  for (int i = 1; i <= 1000000; i++) f[i] = f[i - 1] ^ i;
  for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
  for (int i = 1, ti, tj; i <= m; i++) {
    scanf("%d%d", &ti, &tj);
    v[tj].push_back(make_pair(ti, i));
  }
  for (int i = 1; i <= n; i++) {
    int cur = 0;
    for (int j = i; j <= n; j++) {
      int tmp;
      if (a[i] <= a[j])
        tmp = f[a[j]] ^ f[a[i] - 1];
      else
        tmp = f[a[i]] ^ f[a[j] - 1];
      cur = max(cur, tmp);
      for (auto &x : v[j])
        if (x.first <= i) ans[x.second] = max(ans[x.second], cur);
    }
  }
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}
