N = int(input())
A = list(map(int, input().split()))
ans = 0

if N >= 16:
    print(2**16 - 1)
    exit()


def shift(x):
    return x // 2 + pow(2, 15) * (x % 2)


M = 1 << 16
dp = [False] * M
dp[0] = True
for a in A:
    ndp = [False] * M
    now = a
    for _ in range(16):
        for s in range(M):
            ndp[s | now] |= dp[s]
        now = shift(now)
    dp = ndp[:]
ans = 0
for i in range(M):
    if dp[i]:
        ans = max(ans, i)
print(ans)