n=int(input()) L=1<<16 if n>=16: print(L-1) exit() a=list(map(int,input().split())) q=[0]*L q[0]=1 for v in a: nq=[0]*L for i in range(L): if q[i]: u=v for j in range(16): nq[i|u]=1 u=u//2+(1<<15)*(u%2) q=nq print(max(i for i in range(L) if q[i]))