#include <bits/stdc++.h>
using namespace std;
void fastscan(int &number) {
  bool negative = false;
  register int c;
  number = 0;
  c = getchar();
  if (c == '-') {
    negative = true;
    c = getchar();
  }
  for (; (c > 47 && c < 58); c = getchar()) number = number * 10 + c - 48;
  if (negative) number *= -1;
}
pair<int, int> DP[4 * 1000005];
int ar[1000005];
int N;
pair<int, int> mx(pair<int, int> a, pair<int, int> b) {
  if (a.first == b.first)
    return (pair<int, int>(a.first, max(a.second, b.second)));
  else {
    if (a.first > b.first)
      return (pair<int, int>(a.first, max(a.second, b.first)));
    else
      return (pair<int, int>(b.first, max(b.second, a.first)));
  }
}
int main() {
  fastscan(N);
  for (int i = 0; i < 4 * 1000005; i++) {
    DP[i].first = -1;
    DP[i].second = -1;
  }
  for (int i = 0; i < N; i++) {
    fastscan(ar[i]);
    DP[ar[i]].second = DP[ar[i]].first;
    DP[ar[i]].first = i;
  }
  for (int i = (1 << 21) - 1; i >= 0; i--) {
    for (int j = 0; j < 21; j++) {
      if (i & (1 << j)) DP[i ^ (1 << j)] = mx(DP[i ^ (1 << j)], DP[i]);
    }
  }
  int ans = 0;
  for (int i = N - 3; i >= 0; i--) {
    int sum = 0;
    for (int j = 20; j >= 0; j--) {
      if ((ar[i] & (1 << j)) == 0 && (DP[sum + (1 << j)].second > i))
        sum += (1 << j);
    }
    ans = max(ans, (sum | ar[i]));
  }
  cout << ans << endl;
  return (0);
}
