#include <bits/stdc++.h>
using namespace std;
const int maxn = 1000001, fullVal = (1 << 22) - 1;
pair<int, int> f[1 << 22];
int A[maxn];
inline void add(pair<int, int>& des, pair<int, int> org) {
  if (org.first == des.first || org.first == des.second) {
    org.first = 0;
  }
  if (org.second == des.first || org.second == des.second) {
    org.second = 0;
    swap(org.first, org.second);
  }
  if (org.first > des.second) {
    des = org;
    return;
  }
  if (des.second < org.second) {
    des.first = des.second;
    des.second = org.second;
  } else if (des.first < org.second) {
    des.first = org.second;
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N;
  cin >> N;
  for (int i = 1; i <= N; ++i) {
    cin >> A[i];
    add(f[A[i]], make_pair(0, i));
  }
  for (int i = fullVal; i; --i) {
    for (int j = 1; j <= 22; ++j) {
      if ((1 << ((j)-1)) & i) add(f[i ^ (1 << ((j)-1))], f[i]);
    }
    assert(f[i].first <= f[i].second);
  }
  int ans = 0;
  for (int i = 1; i <= N - 2; ++i) {
    int s = 0;
    for (int j = 22; j; --j) {
      if (((1 << ((j)-1)) & A[i]) == 0 && f[s | (1 << ((j)-1))].first > i)
        s |= (1 << ((j)-1));
    }
    ans = max(ans, (A[i] | s));
  }
  cout << ans << endl;
  return 0;
}
