def f(D): return [D%12,(D+2)%12,(D+4)%12,(D+5)%12,(D+7)%12,(D+9)%12,(D+11)%12] N=int(input()) T=[int(t) for t in input().split()] cnt=0 s=set() for i in range(12): if sum(t in f(i) for t in T)==len(T): cnt+=1 s.add(i) if len(s)==1: print(s.pop()) else: print(-1)