#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long x = 0;
  char ch = getchar();
  bool positive = 1;
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') positive = 0;
  for (; isdigit(ch); ch = getchar()) x = x * 10 + ch - '0';
  return positive ? x : -x;
}
inline void write(long long a) {
  if (a < 0) {
    a = -a;
    putchar('-');
  }
  if (a >= 10) write(a / 10);
  putchar('0' + a % 10);
}
inline void writeln(long long a) {
  write(a);
  puts("");
}
inline void wri(long long a) {
  write(a);
  putchar(' ');
}
inline unsigned long long rnd() {
  return ((unsigned long long)rand() << 30 ^ rand()) << 4 | rand() % 4;
}
const int N = 1 << 20 | 2, m = 21;
int a[N], f[N << 1][2], ans;
int main() {
  int n = read();
  for (int i = (int)(1); i <= (int)(n); i++) {
    a[i] = read();
    f[a[i]][1] = f[a[i]][0];
    f[a[i]][0] = i;
  }
  for (int i = (int)(0); i <= (int)(m - 1); i++)
    for (int j = (int)(0); j <= (int)((1 << m) - 1); j++)
      if (j >> i & 1) {
        if (f[j ^ (1 << i)][0] > f[j][0]) {
          f[j ^ (1 << i)][1] = max(f[j ^ (1 << i)][1], f[j][0]);
        } else {
          f[j ^ (1 << i)][1] = f[j ^ (1 << i)][0];
          f[j ^ (1 << i)][0] = f[j][0];
          f[j ^ (1 << i)][1] = max(f[j ^ (1 << i)][1], f[j][1]);
        }
      }
  for (int i = (int)(1); i <= (int)(n - 2); i++) {
    int dq = 0;
    for (int j = (int)(m - 1); j >= (int)(0); j--)
      if ((a[i] >> j & 1) == 0) {
        if (f[dq | (1 << j)][1] > i) dq |= 1 << j;
      }
    ans = max(ans, a[i] | dq);
  }
  writeln(ans);
}
