n=int(input()) t=list(map(int,input().split())) d=[0,2,4,5,7,9,11] a=[] for i in range(12): ok=True for tt in t: tmp=tt-i tmp%=12 if tmp in d: continue else: ok=False break if ok: a.append(i) if len(a)==1: print(a[0]) else: print(-1)