N=int(input()) T=set(map(int,input().split())) P=[] for i in range(12): if len(set(map(lambda x:x%12,[i,i+2,i+4,i+5,i+7,i+9,i+11]))|T)==7: P.append(i) if len(P)==1: print(P[0]) else: print(-1)