#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
const int LG = 22, N = (1 << LG);
int n, a[N], cnt[N], last[N];
bool mark[N];
vector<int> vec[N];
void go(int p, int ind) {
  if (last[p] == ind || cnt[p] >= 2) return;
  last[p] = ind;
  cnt[p]++;
  if (cnt[p] == 2) vec[ind].push_back(p);
  for (int i = 0; i < LG; i++)
    if (p >> i & 1) go(p ^ (1 << i), ind);
}
inline bool check(int x) {
  for (int i = n - 1; i >= 0; i--) {
    if (i < n - 2) {
      int want = x - (x & a[i]);
      if (mark[want]) return 1;
    }
    for (int x : vec[i]) mark[x] = 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = n - 1; i >= 0; i--) {
    go(a[i], i);
  }
  int ans = 0;
  for (int i = LG - 1; i >= 0; i--) {
    memset(mark, 0, sizeof mark);
    if (check(ans | (1 << i))) ans |= (1 << i);
  }
  cout << ans << '\n';
}
