D=[[d,(d+2)%12,(d+4)%12,(d+5)%12,(d+7)%12,(d+9)%12,(d+11)%12] for d in range(12)] n=int(input()) l=list(map(int,input().split())) a=-1 for x in D: if sum([i in x for i in l])==n: if a==-1: a=x[0] else: a=-1; break print(a)