#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1000100, MAXLA = 21;
int n, a[MAXN], f[(1 << MAXLA)][4], ans;
int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; ++i)
    scanf("%d", &a[i]), f[a[i]][0] = i, sort(f[a[i]], f[a[i]] + 4);
  for (int i = 0, mask; i < MAXLA; ++i)
    for (mask = 0; mask < (1 << MAXLA); ++mask)
      if (mask & (1 << i))
        f[mask ^ (1 << i)][0] = f[mask][2], f[mask ^ (1 << i)][1] = f[mask][3],
                       sort(f[mask ^ (1 << i)], f[mask ^ (1 << i)] + 4);
  for (int i = 1, j, cur = 0; i <= n - 2; ++i, cur = 0) {
    for (j = MAXLA - 1; j >= 0; --j)
      if (((a[i] >> j) & 1) == 0 && f[cur | (1 << j)][2] > i) cur |= (1 << j);
    ans = max(ans, cur | a[i]);
  }
  printf("%d\n", ans);
}
