n = int(input()) t_list = list(map(int, input().split())) candidates = [] for D in range(12): scale = {(D + x) % 12 for x in [0, 2, 4, 5, 7, 9, 11]} valid = True for t in t_list: if t not in scale: valid = False break if valid: candidates.append(D) if len(candidates) == 1: print(candidates[0]) else: print(-1)