#include <bits/stdc++.h>
using namespace std;
const int maxn = 4000005;
int n;
int a[maxn];
struct nod {
  int ans1, ans2;
} dp[maxn];
inline int read() {
  int ret = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -f;
    ch = getchar();
  }
  while (isdigit(ch)) {
    ret = ret * 10 + ch - '0';
    ch = getchar();
  }
  return ret * f;
}
inline void insert(int x, int p) {
  if (x > dp[p].ans1) {
    dp[p].ans2 = dp[p].ans1;
    dp[p].ans1 = x;
    return;
  }
  if (x > dp[p].ans2) dp[p].ans2 = x;
}
void scan() {
  n = read();
  for (int k = 1; k <= n; k++) a[k] = read();
}
void prework() {
  for (int k = 1; k <= n; k++) insert(k, a[k]);
  for (int j = 0; j <= 21; j++) {
    for (int i = maxn - 1; i >= 0; i--)
      if (i & (1 << j)) {
        insert(dp[i].ans1, i ^ (1 << j));
        insert(dp[i].ans2, i ^ (1 << j));
      }
  }
}
void solve() {
  int ans = 0;
  for (int k = 1; k <= n - 2; k++) {
    int now = 0;
    for (int j = 21; j >= 0; j--)
      if (!(a[k] & (1 << j))) {
        int p = (now | (1 << j));
        if (dp[p].ans2 > k) now = p;
      }
    ans = max(ans, (now | a[k]));
  }
  printf("%d\n", ans);
}
signed main() {
  scan();
  prework();
  solve();
  return 0;
}
