n=int(input()) t=list(map(int,input().split())) a=[] for i in range(12): f=1 f&=i in t f&=all((i+j)%12 not in t for j in [1,3,6,8,10]) if f: a+=[i] print(a[0] if len(a)==1 else -1)