n=int(input()) T=list(map(int,input().split())) import collections CT=collections.Counter(T) l=[0,2,4,5,7,9,11] ans=-1 for i in range(12): D=[] for i in l: D.append((i+1)%12) if not (CT-collections.Counter(D)): if ans==-1: ans=i else: exit(print(-1)) print(ans)