#include <bits/stdc++.h>
using namespace std;
const long long inf = 2e18;
const int mod = 1e9 + 7;
const int M = 5003;
const int N = 50004;
const int MX = 1000006;
int n, m;
int a[N];
int lft[M], rgt[M], ses[M];
int pre_xr[MX];
int yo[N];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> n >> m;
  for (int i = 1; i <= n; i++) cin >> a[i];
  for (int i = 1; i <= MX - 1; i++) {
    pre_xr[i] = pre_xr[i - 1] ^ i;
  }
  for (int i = 1; i <= m; i++) {
    cin >> lft[i] >> rgt[i];
  }
  for (int i = 1; i <= n; i++) {
    int mx = 0;
    for (int j = i; j <= n; j++) {
      int mn = (a[i] < a[j]) ? a[i] : a[j];
      int z = pre_xr[a[i]] ^ pre_xr[a[j]] ^ mn;
      mx = max(mx, z);
      yo[j] = mx;
    }
    for (int j = 1; j <= m; j++) {
      if (lft[j] <= i) {
        ses[j] = max(ses[j], yo[rgt[j]]);
      }
    }
  }
  for (int i = 1; i <= m; i++) {
    cout << ses[i] << "\n";
  }
  return 0;
}
