n = int(input()) tlst = list(map(int, input().split())) dd = [0, 2, 4, 5, 7, 9, 11] cand = [] for i in range(12): lst = [] for d in dd: lst.append((i + d) % 12) for t in tlst: if t not in lst: break else: cand.append(i) if len(cand) == 1: print(cand[0]) else: print(-1)