#include <bits/stdc++.h>
using namespace std;
struct marray {
  int value[2], size;
};
void merge(marray &x, const marray &y) {
  for (int i = 0; i < y.size; ++i) {
    if (x.size < 2) {
      x.value[x.size++] = y.value[i];
    } else {
      if (x.value[0] < y.value[i]) {
        x.value[0] = y.value[i];
      } else if (x.value[1] < y.value[i]) {
        x.value[1] = y.value[i];
      }
    }
    if (x.size == 2 && x.value[0] > x.value[1]) {
      swap(x.value[0], x.value[1]);
    }
  }
}
marray dp[2097152];
int a[2097152];
void init() {
  for (int i = 0; i < 2097152; ++i) {
    dp[i].size = 0;
  }
}
void solve() {
  init();
  int n;
  scanf("%d ", &n);
  for (int i = 0; i < n; ++i) {
    scanf("%d ", &a[i]);
    marray tmp;
    tmp.size = 1;
    tmp.value[0] = i;
    merge(dp[a[i]], tmp);
  }
  for (int bit = 0; bit < 21; ++bit) {
    for (int i = 2097152 - 1; i >= 0; --i) {
      if ((i & (1 << bit)) == 0) {
        int g = i | (1 << bit);
        assert(g < 2097152);
        merge(dp[i], dp[g]);
      }
    }
  }
  int ret = 0;
  for (int i = 0; i < n - 2; ++i) {
    int maxBit = 0;
    for (int bit = 21 - 1; bit >= 0; --bit) {
      if (a[i] & (1 << bit)) {
        continue;
      }
      int cur = maxBit | (1 << bit);
      if (dp[cur].size == 2 && i < dp[cur].value[0]) {
        maxBit = cur;
      }
    }
    ret = max(ret, maxBit | a[i]);
  }
  printf("%d\n", ret);
}
int main() {
  solve();
  return 0;
}
