#include <bits/stdc++.h>
using namespace std;
const int maxl = 3e6 + 10;
int n, ans;
int a[maxl];
int mx[maxl], sec[maxl];
inline void upd(int i, int x) {
  if (x > mx[i])
    sec[i] = mx[i], mx[i] = x;
  else if (x > sec[i])
    sec[i] = x;
}
inline void prework() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    upd(a[i], i);
  }
  int up = 1 << 21;
  for (int j = 0; j < 20; j++)
    for (int i = 0; i < up; i++)
      if (!((i >> j) & 1)) {
        upd(i, mx[i ^ (1 << j)]);
        upd(i, sec[i ^ (1 << j)]);
      }
}
inline void mainwork() {
  int now;
  ans = 0;
  for (int i = 1; i <= n - 2; i++) {
    now = 0;
    for (int j = 20; j >= 0; j--) {
      if ((a[i] >> j) & 1) continue;
      if (sec[now ^ (1 << j)] > i) now ^= (1 << j);
    }
    ans = max(ans, now | a[i]);
  }
}
inline void print() { printf("%d", ans); }
int main() {
  prework();
  mainwork();
  print();
  return 0;
}
