#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9;
inline void gmx(int &x, int y) {
  if (x < y) x = y;
}
inline void gmn(int &x, int y) {
  if (x > y) x = y;
}
inline int read() {
  char c = getchar();
  int z = 0, f = 1;
  while (c != '-' && (c > '9' || c < '0')) c = getchar();
  if (c == '-') f = -1, c = getchar();
  while (c >= '0' && c <= '9') z = (z << 1) + (z << 3) + c - '0', c = getchar();
  return z * f;
}
const int N = 1 << 22;
pair<int, int> f[N];
int n, a[N], R, ans, tmp;
inline void ins(pair<int, int> &x, int k) {
  k > x.first ? x.second = x.first, x.first = k : x.second = max(x.second, k);
}
inline int check(int x, int pos) { return f[x].second > pos; }
int main() {
  n = read();
  R = (1 << 21) - 1;
  for (register int i = 1; i <= n; i++) ins(f[a[i] = read()], i);
  for (register int j = 0; j <= 20; j++)
    for (register int i = 0; i <= R; i++)
      if (!(i & (1 << j)))
        ins(f[i], f[i ^ (1 << j)].first), ins(f[i], f[i ^ (1 << j)].second);
  for (register int i = 1, j; i < n - 1; gmx(ans, tmp | a[i]), i++)
    for (tmp = 0, j = 20; ~j; j--)
      if (!(a[i] & (1 << j))) tmp += check(tmp + (1 << j), i) * (1 << j);
  cout << ans;
  return 0;
}
