#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
inline void read(int& x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  x *= f;
}
const int M = (1 << 21) + 7;
vector<int> pos[M];
inline void addPos(vector<int>& ms, int p) {
  if (ms.empty())
    ms.push_back(p);
  else if (ms.size() == 1) {
    if (ms[0] > p) {
      ms.push_back(p);
      swap(ms[0], ms[1]);
    } else if (ms[0] < p)
      ms.push_back(p);
  } else {
    if (ms[0] > p)
      ;
    else if (ms[1] != p)
      ms[0] = p;
    if (ms[0] > ms[1]) swap(ms[0], ms[1]);
  }
}
inline void upd(vector<int>& A, vector<int>& B) {
  for (int e : B) addPos(A, e);
}
int main() {
  int n;
  read(n);
  vector<int> a(n + 1);
  int maxi = 0;
  for (int i = 1; i <= n; ++i) {
    read(a[i]);
    maxi = max(maxi, a[i]);
    addPos(pos[a[i]], i);
  }
  for (int m = maxi; m; --m) {
    for (int b = 0; b < 22; ++b)
      if (~m >> b & 1) {
        if ((m | (1 << b)) <= maxi) upd(pos[m], pos[m | (1 << b)]);
      }
  }
  int ans = 0;
  for (int i = 1; i <= n - 2; ++i) {
    int cur = 0;
    for (int b = 21; ~b; --b) {
      if (~a[i] >> b & 1) {
        auto& it = pos[cur | 1 << b];
        if (it.size() == 2 && *it.begin() > i) {
          cur |= 1 << b;
        }
      }
    }
    ans = max(ans, a[i] | cur);
  }
  cout << ans << endl;
  return 0;
}
