import sys input=sys.stdin.readline def I(): return int(input()) def MI(): return map(int, input().split()) def LI(): return list(map(int, input().split())) def main(): mod=10**9+7 N=I() T=LI() L=[0,2,4,5,7,9,11] F=[0]*12 for d in range(12): flag=1 for j in range(N): a=(T[j]-d)%12 if not(a in L): flag=0 if flag: F[d]=1 if sum(F)==1: for i in range(12): if F[i]==1: print(i) exit() else: print(-1) main()