N = int(input()) T = list(map(int,input().split())) t = set(T) mod = 12 a = (0,2,4,5,7,9,11) ans = [] for d in range(12): s = set() for k in a: s.add((d + k) % mod) if t <= s: ans.append(d) if len(ans) == 1: print(ans[0]) else: print(-1)