# BIT DP を行う # A[i] > 0 だから, 最大16個見ればok # dp[i][j] : i番目まで見てjが到達可能 n = int(input()) a = list(map(int,input().split())) dp = [[0] * (1 << 16) for i in range(min(n, 16) + 1)] dp[0][0] = 1 for i in range(min(n, 16)): for j in range(16): for k in range(1 << 16): if dp[i][k] == 1: dp[i+1][k|a[i]] = 1 a[i] = (a[i] // 2) + (1 << 15) * (a[i] % 2) r = 0 for i in range(1 << 16): if dp[min(n, 16)][i] == 1: r = i print(r)