def shift(x): return ((x % 2) << 15) + x//2 N =int(input()) A = list(map(int, input().split())) dp = [0] * (N + 1) L = [] for i in range(N): p = A[i] for j in range(16): v = p for a in L: v |= a if v not in L: L.append(p) break p = shift(p) dp = [0] * (1 << 16) dp[0] = 1 M = len(L) pre = set([0]) for i in range(M): S = set() v = A[i] for s in range(1 << 16): for j in range(16): if dp[s]: S.add(s|v) v = shift(v) for b in S: dp[b] = 1 for c in pre: dp[c] = 0 pre, S = S, pre for i in range(2 ** 16 - 1, -1, -1): if dp[i]: print(i) break