N,*T=map(int, open(0).read().split()) x=[0,2,4,5,7,9,11] r=-1 for i in range(12): t = set((i+e)%12 for e in x) for e in T: if e not in t: break else: if r==-1: r=i else: print(-1) exit() print(r)