N=int(input()) T=list(map(int, input().split())) A=[0,2,4,5,7,9,11] ans=[] for i in range(12): D=[] for j in A: D.append((i+j)%12) if len(set(D)&set(T))==len(T): ans.append(i) if len(ans)==1: print(ans[0]) else: print(-1)