N = int(input()) T = [int(t) for t in input().split()] ans = -1 for i in range(12): L = [i, i+2, i+4, i+5, i+7, i+9, i+11] for j in range(len(L)): L[j] %= 12 flag = True for t in T: if not t in L: flag = False break if flag: if ans > -1: ans = -1 break ans = i print(ans)