from collections import defaultdict, deque from heapq import heappush, heappop from itertools import permutations, accumulate import sys import math import bisect def LI(): return [int(x) for x in sys.stdin.readline().split()] def I(): return int(sys.stdin.readline()) def IR(n): return [I() for _ in range(n)] def LIR(n): return [LI() for _ in range(n)] sys.setrecursionlimit(1000000) mod = 1000000007 def main(): def shift(x): return (x>>1)+((x&1)<<15) n = I() a = LI() m = 2**16 if n > 15: print(m-1) return f = [0]*m f[0] = 1 for i in a: nf = [0]*m for _ in range(16): for x in range(m): if not f[x]: continue nf[x|i] = 1 i = shift(i) f = nf for i in reversed(range(m)): if f[i]: print(i) return return if __name__ == "__main__": main()