input() u={int(n) for n in input().split()} p=[i for i in range(12) if u<={(i+n)%12 for n in [0,2,4,5,7,9,11]}] print(-1 if len(p)!=1 else p[0])