from typing import List, Tuple, Optional import sys import itertools import heapq import bisect from collections import deque, defaultdict from functools import lru_cache, cmp_to_key input = sys.stdin.readline # for AtCoder Easy test if __file__ != 'prog.py': sys.setrecursionlimit(10 ** 6) def readints(): return map(int, input().split()) def readlist(): return list(readints()) def readstr(): return input().rstrip() N = int(input()) A = readlist() if N > 15: print((1 << 16) - 1) exit() dp = [False] * (1 << 16) dp[0] = True for a in A: ndp = [False] * (1 << 16) for j in range(1 << 16): if dp[j] is False: continue acc = a for k in range(16): ndp[j | acc] = True if acc & 1: acc = (acc >> 1) + (1 << 15) else: acc = (acc >> 1) dp = ndp for s in range(1 << 16)[::-1]: if dp[s] is True: print(s) break