#include <bits/stdc++.h>
using namespace std;
namespace red {
inline int read() {
  int x = 0;
  char ch, f = 1;
  for (ch = getchar(); (ch < '0' || ch > '9') && ch != '-'; ch = getchar())
    ;
  if (ch == '-') f = 0, ch = getchar();
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + ch - '0';
    ch = getchar();
  }
  return f ? x : -x;
}
const int N = 2e6 + 10, inf = 1 << 30;
int n, ans;
int a[N];
pair<int, int> dp[N];
inline void update(int x, int pos) {
  if (dp[x].first < pos) {
    dp[x].second = dp[x].first;
    dp[x].first = pos;
  } else if (dp[x].second < pos && pos != dp[x].first)
    dp[x].second = pos;
}
inline void SOSdp() {
  for (int s = N - 1; ~s; --s) {
    for (int i = 20; ~i; --i) {
      if ((s >> i) & 1) {
        update(s ^ (1 << i), dp[s].first);
        update(s ^ (1 << i), dp[s].second);
      }
    }
  }
}
inline void main() {
  n = read();
  for (int i = 1; i <= n; ++i) a[i] = read(), update(a[i], i);
  SOSdp();
  for (int i = 1; i <= n - 2; ++i) {
    int w = 0;
    for (int j = 20; ~j; --j) {
      if (!((a[i] >> j) & 1) && dp[w | (1 << j)].first > i &&
          dp[w | (1 << j)].second > i)
        w = w | (1 << j);
    }
    ans = max(ans, a[i] | w);
  }
  printf("%d", ans);
}
}  // namespace red
signed main() {
  red::main();
  return 0;
}
