#include <bits/stdc++.h>
using namespace std;
int n;
int a[2000005];
int flag[2100005];
int mx[2100005];
int q[2100005];
int t[2100005];
int tot = 0, ttt = 0;
int ff[2100005];
int vis[2100005];
int best;
int b[2000005];
int ans = 0;
int out(int now) {
  for (int i = 20; i >= 0; i--)
    if ((1 << i) & now)
      cout << 1;
    else
      cout << 0;
  return 0;
}
void mak(int now) {
  int head, tail;
  head = tail = 1;
  t[head] = now;
  mx[now] = now;
  while (head <= tail) {
    int s = t[head++];
    for (int j = 0; j < 21; j++)
      if (((1 << j) & s) == 0 && mx[(s ^ (1 << j))] < now) {
        mx[(s ^ (1 << j))] = now;
        t[++tail] = (s ^ (1 << j));
      }
  }
  return;
}
void ins(int s) {
  int now = 1;
  for (int i = 20; i >= 0; i--) {
    if ((1 << i) & s)
      now = ((now << 1) | 1);
    else
      now = now << 1;
    vis[now] = 1;
  }
  return;
}
void query(int s, int now, int pos) {
  ttt++;
  if (ttt >= 100) return;
  int temp = (now ^ (1 << (20 - pos)));
  temp = temp << (pos + 1);
  ans = max(ans, s | temp);
  if (pos == -1) return;
  if (ans >= (s | (temp | ((1 << (pos + 1)) - 1)))) return;
  if (((1 << pos) & s) == 0) {
    if (vis[(now << 1) | 1])
      query(s, (now << 1) | 1, pos - 1);
    else
      query(s, (now << 1), pos - 1);
  } else {
    query(s, (now << 1), pos - 1);
    query(s, (now << 1) | 1, pos - 1);
  }
  return;
}
void bfs(int now) {
  tot++;
  if (flag[now] >= 2) return;
  int head, tail;
  head = tail = 1;
  q[head] = now;
  flag[now]++;
  ff[now] = tot;
  while (head <= tail) {
    int s = q[head++];
    if (flag[s] == 2) ins(s);
    for (int j = 0; j < 21; j++)
      if (((1 << j) & s) != 0 && flag[s ^ (1 << j)] < 2 &&
          ff[s ^ (1 << j)] != tot) {
        ff[s ^ (1 << j)] = tot;
        flag[s ^ (1 << j)]++;
        q[++tail] = (s ^ (1 << j));
      }
  }
}
int main() {
  std::ios::sync_with_stdio(false);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> b[i];
  }
  int tot = n;
  n = 0;
  for (int i = 1; i <= tot; i++) {
    if (i >= 3 && b[i] == b[i - 1] && b[i - 1] == b[i - 2] &&
        b[i - 2] == b[i - 3])
      continue;
    a[++n] = b[i];
  }
  for (int i = n; i >= 1; i--) {
    if (i <= n - 2) {
      ttt = 0;
      int t = (1 << 21) - 1;
      best = 0;
      query(a[i], 1, 20);
    }
    bfs(a[i]);
  }
  cout << ans << endl;
}
