#include <bits/stdc++.h>
using namespace std;
template <typename T>
void chkmin(T &a, T b) {
  a = min(a, b);
}
template <typename T>
void chkmax(T &a, T b) {
  a = max(a, b);
}
inline int fread(void) {
  int ret = 0, op = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') op = -1;
  for (; isdigit(ch); ch = getchar()) ret = (ret << 1) + (ret << 3) - '0' + ch;
  return ret * op;
}
const int MAXN = 3e6 + 10;
const int INF = 0x3f3f3f3f;
const int MAXM = 22 + 10;
pair<int, int> f[MAXN];
int n, a[MAXN];
pair<int, int> smax(pair<int, int> x, pair<int, int> y) {
  if (x.first < y.first) swap(x, y);
  pair<int, int> ret = x;
  ret.second = max(x.second, y.first);
  return ret;
}
inline void init(void) {
  n = fread();
  for (int i = 1; i <= n; ++i) {
    a[i] = fread();
    f[a[i]] = smax(f[a[i]], make_pair(i, -INF));
  }
}
void SoSDP(void) {
  for (int i = 0; i < 21; ++i) {
    for (int mask = 0; mask < (1 << 21); ++mask) {
      if (!((mask >> i) & 1)) {
        f[mask] = smax(f[mask], f[mask | (1 << i)]);
      }
    }
  }
}
bool check(int S, int pos) { return f[S].second > pos; }
inline void work(void) {
  SoSDP();
  int ans = 0;
  for (int i = 1; i <= n - 2; ++i) {
    int now = 0;
    for (int j = 21; j >= 0; --j) {
      if ((a[i] >> j) & 1) continue;
      if (check(now ^ (1 << j), i)) now ^= (1 << j);
    }
    ans = max(ans, now | a[i]);
  }
  printf("%d", ans);
}
int main() {
  init();
  work();
  return 0;
}
