#include <bits/stdc++.h>
using namespace std;
const int BITS = 21;
const int N = 1e6 + 111;
int n, A[N];
pair<int, int> P[1 << BITS];
int res;
void Update(int mask, int pos) {
  if (P[mask].first == -1)
    P[mask].first = pos;
  else if (P[mask].second == -1) {
    if (P[mask].first < pos)
      P[mask].second = pos;
    else if (pos < P[mask].first) {
      P[mask].second = P[mask].first;
      P[mask].first = pos;
    }
  } else {
    if (P[mask].second < pos) {
      P[mask].first = P[mask].second;
      P[mask].second = pos;
    } else if (P[mask].first < pos)
      P[mask].first = pos;
  }
}
void Merge(int mask_1, int mask_2) {
  if (P[mask_2].first != -1) Update(mask_1, P[mask_2].first);
  if (P[mask_2].second != -1) Update(mask_1, P[mask_2].second);
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> n;
  for (int i = 1; i <= n; ++i) cin >> A[i];
  memset(P, -1, sizeof(P));
  for (int i = 1; i <= n; ++i) Update(A[i], i);
  for (int i = 0; i < BITS; ++i) {
    for (int mask = 0; mask < (1 << BITS); ++mask) {
      if (mask & (1 << i)) {
        Merge(mask ^ (1 << i), mask);
      }
    }
  }
  for (int i = 1; i <= n; ++i) {
    int off_bit = (1 << BITS) - 1 - A[i];
    int opt = 0;
    for (int j = BITS - 1; j >= 0; --j) {
      if (off_bit & (1 << j)) {
        if (P[opt | (1 << j)].second != -1 && P[opt | (1 << j)].first > i)
          opt |= (1 << j);
      }
    }
    if (P[opt].second != -1 && P[opt].first > i) res = max(res, (A[i] | opt));
  }
  cout << res << '\n';
  return 0;
}
