n = int(input())
t = list(map(int, input().split()))
cho = [0, 2, 4, 5, 7, 9, 11]
c = 0
ans = 0
for i in range(12):
    f = False
    for j in t:
        if not (((j - i) % 12) in cho):
            f = True
            break
    if not f:
        c = i
        ans += 1
if ans == 1:
    print(c)
else:
    print(-1)