#include <bits/stdc++.h>
using namespace std;
int n, m, ar[50010], xo[1000010], ans[5010], now[50010];
pair<int, int> p[5010];
int main() {
  ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  for (int i = 1; i <= 1000003; i++) xo[i] = xo[i - 1] ^ i;
  cin >> n >> m;
  for (int i = 0; i < n; i++) cin >> ar[i];
  for (int i = 0; i < m; i++) {
    cin >> p[i].first >> p[i].second;
    p[i].first--;
    p[i].second--;
  }
  for (int i = 0; i < n; i++) {
    int cnt = 0;
    for (int j = i; j < n; j++) {
      if (ar[j] < ar[i])
        cnt = max(cnt, xo[ar[j] - 1] ^ xo[ar[i]]);
      else
        cnt = max(cnt, xo[ar[i] - 1] ^ xo[ar[j]]);
      now[j] = cnt;
    }
    for (int j = 0; j < m; j++)
      if (p[j].first <= i && p[j].second >= i)
        ans[j] = max(ans[j], now[p[j].second]);
  }
  for (int i = 0; i < m; i++) cout << ans[i] << endl;
}
