n = int(input()) if n >= 16: print((1 << 16) - 1) exit() A = list(map(int, input().split())) DP = [[False for _ in range(1 << 16)] for _ in range(n + 1)] header = 1 << 15 for i in range(n + 1): DP[i][0] = True for i in range(n): a = A[i] for j in range(16): for k in range(1 << 16): if DP[i][k]: DP[i + 1][k | a] |= DP[i][k] a, r = divmod(a, 2) a |= header * r for i in range((1 << 16) - 1, 0, -1): if DP[n][i]: print(i) break