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