#include <bits/stdc++.h>
using namespace std;
int n, m, a[2100005], f[2100005][2];
inline void Add(int v, int x) {
  if (f[v][0] < x)
    f[v][1] = f[v][0], f[v][0] = x;
  else if (f[v][1] < x)
    f[v][1] = x;
}
signed main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
    Add(a[i], i);
  }
  for (int i = 0; i < 21; i++)
    for (int j = 0; j < (1 << 21); j++) {
      if (j & (1 << i)) continue;
      if (f[j | (1 << i)][0] != 0) Add(j, f[j | (1 << i)][0]);
      if (f[j | (1 << i)][1] != 0) Add(j, f[j | (1 << i)][1]);
    }
  int ans = 0;
  for (int i = 1; i <= n - 2; i++) {
    int res = 0;
    for (int j = 20; j >= 0; j--) {
      if (!(a[i] & (1 << j))) {
        res |= 1 << j;
        if (f[res][1] <= i) res ^= 1 << j;
      }
    }
    ans = max(ans, res | a[i]);
  }
  printf("%d\n", ans);
  return 0;
}
