#include <bits/stdc++.h>
using namespace std;
int N;
int A[1000005];
int ans;
const int maxBit = 21;
pair<int, int> Max[4000005];
void updateMax(pair<int, int>& curr, int val) {
  if (curr.first == val || curr.second == val) return;
  if (curr.first < val) {
    curr.second = curr.first;
    curr.first = val;
  } else if (curr.second < val)
    curr.second = val;
}
void precalcMax() {
  for (int i = N; i >= 1; i--) {
    updateMax(Max[A[i]], i);
  }
  for (int i = (1 << maxBit) - 1; i >= 0; i--) {
    for (int j = 0; j < maxBit; j++) {
      if (!(i & (1 << j))) {
        updateMax(Max[i], Max[i ^ (1 << j)].first);
        updateMax(Max[i], Max[i ^ (1 << j)].second);
      }
    }
  }
}
void Read() {
  scanf("%d", &N);
  for (int i = 1; i <= N; i++) scanf("%d", &A[i]);
}
void Solve() {
  for (int i = N - 2; i >= 1; i--) {
    int mask = ((1 << maxBit) - 1) ^ (A[i]);
    int res = 0;
    for (int j = maxBit - 1; j >= 0; j--) {
      if (!(mask & (1 << j))) continue;
      if (Max[res ^ (1 << j)].second > i) res ^= (1 << j);
    }
    ans = max(ans, res | A[i]);
  }
  printf("%d\n", ans);
}
int main() {
  Read();
  precalcMax();
  Solve();
  return 0;
}
