n=int(input()) *t,=map(int,input().split()) ans=[] h=[0,2,4,5,7,9,11] for i in range(12): flg=True for j in range(n): if (t[j]-i)%12 not in h: flg=False if flg: ans.append(i) if len(ans)==1: print(ans[0]) else: print(-1)