import sys n = int(input()) t_i = [int(i) for i in input().split()] l = [0, 2, 4, 5, 7, 9, 11] ans = [] for i in range(12): new_l = [(i + j) % 12 for j in l] flg = False for t in t_i: if not t in new_l: flg = True break if flg: continue else: ans.append(i) if len(ans) == 1: print(ans[0]) else: print(-1)