#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;
const long long MOD2 = 998244353;
const long long N = (1LL << 22);
const long double pi = 3.14159265359;
long long ans, n, u[N];
pair<long long, long long> dp[N];
void update(long long ida, long long idb) {
  if (dp[idb].first > dp[ida].second) {
    if (dp[idb].first > dp[ida].first) {
      dp[ida].second = max(dp[ida].first, dp[idb].second);
      dp[ida].first = dp[idb].first;
    } else
      dp[ida].second = dp[idb].first;
  }
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin >> n;
  for (long long i = 0; i < n; i++) cin >> u[i];
  for (long long i = 0; i < N; i++) dp[i] = make_pair(-1, -1);
  for (long long i = n - 1; i >= 0; i--) {
    if (dp[u[i]].first == -1)
      dp[u[i]].first = i;
    else if (dp[u[i]].second == -1)
      dp[u[i]].second = i;
  }
  for (long long j = 0; j < 22; j++) {
    for (long long i = N - 1; i >= 0; i--) {
      if (((1LL << j) & i)) continue;
      update(i, (i | (1LL << j)));
    }
  }
  for (long long i = 0; i < n - 2; i++) {
    long long tmp = 0;
    for (long long j = 21; j >= 0; j--) {
      if (((1LL << j) & u[i])) continue;
      if (dp[(tmp | (1LL << j))].second > i) tmp |= (1LL << j);
    }
    ans = max(ans, (tmp | u[i]));
  }
  cout << ans << "\n";
  return 0;
}
