#include <iostream>
#include <vector>
using namespace std;
using ll = long long;
ll N;
inline ll macs(ll a, ll b) {
if (a > b) return a;
return b;
}
int main() {
// freopen("rose.in","r",stdin);
// freopen("rose.out","w",stdout);
ios_base::sync_with_stdio(0);z
cin.tie(0), cout.tie(0);
cin >> N;
vector<ll> num;
num.push_back(0);
vector<ll> pos(50);
ll tmp;
for (ll i=1; i<=N; i++) {
cin >> tmp;
num.push_back(tmp);
}
ll ans = 0, mx = 0;
vector<ll> dp(N+1, 0);
dp[0] = dp[1] = 0;
for (ll i=1; i<=N; i++) {
dp[i] = mx;
for (ll j=0; j<=40; j++) {
if (num[i]>>j & 1) {
dp[i] = macs(dp[i], dp[pos[j]]+(num[i]&num[pos[j]]));
pos[j] = i;
}
}
ans = macs(dp[i], ans);
mx = macs(dp[i], mx);
}
cout << ans;
return 0;
}