N = int(input()) T = list(map(int, input().split())) ans = [] TT = [0, 2, 4, 5, 7, 9, 11] for d in range(12): L = [] for tt in TT: L.append((tt + d) % 12) for t in T: if t not in L: break else: ans.append(d) print(ans[0]) if len(ans) == 1 else print(-1)