n = int(input()) T = list(map(int, input().split())) ANS = [] for d in range(12): seen = [False for _ in range(n)] for t in [0, 2, 4, 5, 7, 9, 11]: c = (d + t) % 12 for i in range(n): if T[i] == c: seen[i] = True break flag = True for i in range(n): if not seen[i]: flag = False break if flag: ANS.append(d) if len(ANS) == 1: print(ANS[0]) else: print(-1)