N = int(input()) T = list(map(int,input().split())) C = [0,2,4,5,7,9,11] cands = [] for i in range(12): A = [(c+i)%12 for c in C] if all(t in A for t in T): cands.append(i) print(cands[0] if len(cands)==1 else -1)