#include <bits/stdc++.h>
#pragma GCC optimize("O3")
using namespace std;
template <class C>
void mini(C &a4, C b4) {
  a4 = min(a4, b4);
}
template <class C>
void maxi(C &a4, C b4) {
  a4 = max(a4, b4);
}
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << '=' << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << '=' << h << ',';
  _dbg(sdbg + 1, a...);
}
template <class T>
ostream &operator<<(ostream &os, vector<T> V) {
  os << "[";
  for (auto vv : V) os << vv << ",";
  return os << "]";
}
template <class L, class R>
ostream &operator<<(ostream &os, pair<L, R> P) {
  return os << "(" << P.first << "," << P.second << ")";
}
const long long C = 21;
const long long MAX = 1 << C;
vector<long long> pier, ost, dru, t;
long long n;
void dodaj_pier(long long id, long long val) {
  (id, val);
  if (pier[val] == n) {
    pier[val] = id;
    for (long long bit = (0); bit <= ((long long)(C)-1); bit++)
      if ((val >> bit) & 1) {
        dodaj_pier(id, val - (1 << bit));
      }
  }
}
void dodaj_ost(long long id, long long val) {
  if (ost[val] != id && (ost[val] == -1 || dru[val] == -1)) {
    if (ost[val] == -1)
      ost[val] = id;
    else
      dru[val] = id;
    for (long long bit = (0); bit <= ((long long)(C)-1); bit++)
      if ((val >> bit) & 1) {
        dodaj_ost(id, val - (1 << bit));
      }
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(11);
  if (0) cout << fixed << setprecision(6);
  cin >> n;
  t.resize(n);
  pier.resize(MAX, n);
  ost.resize(MAX, -1);
  dru.resize(MAX, -1);
  for (long long i = (0); i <= ((long long)(n)-1); i++) cin >> t[i];
  for (long long i = (0); i <= ((long long)(n)-1); i++) {
    dodaj_pier(i, t[i]);
  }
  for (long long i = n - 1; i >= 0; i--) {
    dodaj_ost(i, t[i]);
  }
  (pier, ost, dru);
  (pier[0], dru[0], dru[4]);
  long long res = 0;
  vector<pair<long long, long long> > ok;
  ok.push_back({0ll, 0ll});
  for (long long bit = C - 1; bit >= 0; bit--) {
    long long pom = 1 << bit;
    vector<pair<long long, long long> > ok2;
    for (pair<long long, long long> el : ok) {
      if (pier[el.first + pom] < dru[el.second]) {
        ok2.push_back({el.first + pom, el.second});
      }
      if (pier[el.first] < dru[el.second + pom]) {
        ok2.push_back({el.first, el.second + pom});
      }
    }
    if (((long long)(ok2).size())) {
      res += pom;
      swap(ok, ok2);
    }
    (ok);
  }
  cout << res << "\n";
}
