import sys input=lambda:sys.stdin.readline().rstrip() N=int(input()) A=list(map(int,input().split())) if N>15: print(2**16-1) else: pos=[i==0 for i in range(2**16)] for i in A: temp=i newpos=[i==0 for i in range(2**16)] for k in range(16): temp=(temp//2)+(2**15)*(temp%2) for j in range(2**16): if pos[j]: newpos[j|temp]=1 pos=newpos for i in range(2**16-1,-1,-1): if pos[i]: print(i) break