#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e6 + 100, inf = 2e6;
bool cur1;
int n;
int A[maxn];
struct node {
  int num[2];
  node operator+(const node &_) const {
    node res;
    int i = 0, j = 0;
    if (num[i] > _.num[j])
      res.num[0] = num[i++];
    else
      res.num[0] = _.num[j++];
    if (num[i] > _.num[j])
      res.num[1] = num[i++];
    else
      res.num[1] = _.num[j++];
    return res;
  }
} sum[maxn << 1];
bool cur2;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) scanf("%d", &A[i]);
  for (int i = 1; i <= n; i++) {
    node tmp;
    tmp.num[0] = i;
    sum[A[i]] = sum[A[i]] + tmp;
  }
  for (int i = 0; i <= 20; i++)
    for (int j = 0; j <= inf; j++) {
      if (1 << i & j) sum[j ^ 1 << i] = sum[j ^ 1 << i] + sum[j];
    }
  int ans = 0;
  for (int i = 1; i <= n - 2; i++) {
    int now = 0;
    int x = A[i];
    for (int j = 20; j >= 0; j--) {
      if (1 << j & x) continue;
      int nxt = now ^ 1 << j;
      if (sum[nxt].num[1] > i) now ^= 1 << j;
    }
    ans = max(ans, now | A[i]);
  }
  cout << ans << endl;
  return 0;
}
