N = int(input()) T = list(map(int,input().split())) ans = [] mod = 12 for D in range(13): flag = True for t in T: if t not in [D % mod,(D+2)%mod,(D+4)%mod,(D+5)%mod,(D+7)%mod,(D+9)%mod,(D+11)%mod]: flag = False break if flag: ans.append(D) if len(ans) == 1: print (ans[0]) else: print (-1)