n = int(input()) T = list(map(int,input().split())) ans = -1 def check(x): for t in T: ok = 0 for j in ((0,2,4,5,7,9,11)): if t == (x+j)%12: ok = 1 if ok == 0: return False return True for i in range(12): if check(i): if ans != -1: print(-1) exit() ans = i print(ans)