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