import sys sys.setrecursionlimit(10 ** 6) stdin = sys.stdin ni = lambda: int(ns()) na = lambda: list(map(int, stdin.readline().split())) ns = lambda: stdin.readline().strip() nsa = lambda: list(stdin.readline().split()) mod = 10 * 7 + 7 n = ni() T = na() D = (0, 2, 4, 5, 7, 9, 11) Ans = [] for i in range(12): flag = True Di = set(map(lambda x: (x + i) % 12, D)) for t in T: if not(t in Di): flag = False break if flag: Ans.append(i) if len(Ans) == 1: print(Ans[0]) else: print(-1)