#include <bits/stdc++.h>
using namespace std;
inline int read() {
  register int x(0), f(1);
  register char c(getchar());
  while (c > '9' || c < '0') f = c == '-' ? -1 : 1, c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - 48, c = getchar();
  return f * x;
}
const int N = 2e6 + 10;
int n, a[N], ans, f[N][3], limit, maxn;
void add(int val, int x) {
  if (!f[val][1])
    f[val][1] = x;
  else if (!f[val][2])
    f[val][2] = x;
  else {
    if (f[val][2] < x)
      f[val][1] = f[val][2], f[val][2] = x;
    else if (f[val][1] < x)
      f[val][1] = x;
  }
  if (f[val][1] > f[val][2] && f[val][2]) swap(f[val][1], f[val][2]);
}
void up(int v, int u) {
  if (f[u][1]) add(v, f[u][1]);
  if (f[u][2]) add(v, f[u][2]);
}
int main() {
  register int i, j;
  n = read();
  for (i = 1; i <= n; i++) a[i] = read(), maxn = max(maxn, a[i]);
  limit = log2(maxn);
  maxn = (1 << (limit + 1)) - 1;
  for (i = n; i >= 1; i--) add(a[i], i);
  for (i = 0; i <= limit; i++)
    for (j = 0; j <= maxn; j++)
      if (j & (1 << i)) up(j ^ (1 << i), j);
  for (i = 1; i <= n; i++) {
    int now = 0, nowmax = maxn - a[i];
    for (j = limit; j >= 0; j--)
      if (nowmax & (1 << j)) {
        int to = (now | (1 << j));
        if (f[to][1] > i && f[to][2]) now = to;
      }
    if (f[now][1] > i && f[now][2]) ans = max(ans, a[i] | now);
  }
  cout << ans;
  return 0;
}
