# coding: utf-8 # Your code here! N = int(input()) T = list(map(int,input().split())) R = (0,2,4,5,7,9,11) def check(t,d): candi = set() for r in R: candi.add((d + r) % 12) for t in T: if t not in candi: return False return True ans = None for D in range(12): # その調ですべてのTが当てはまるかチェック if check(T,D): if ans is None: ans = D else: print(-1) exit(0) if ans is None: print(-1) else: print(ans)