x = [0, 2, 4, 5, 7, 9, 11] ans = [] N = int(input()) T = list(map(int, input().split())) for i in range(12): if all((t - i) % 12 in x for t in T): ans += [i] if len(ans) == 1: print(ans[0]) else: print(-1)