N = int(input()) T = [int(t) for t in input().split()] mod = 12 ans = [] for i in range(N): c = [0,2,4,5,7,9,11] for j in range(7): c[j] += T[i] c[j] = c[j]%mod #print(c) cnt = 0 for t in T: if t in c: cnt += 1 if cnt == N: ans.append(T[i]) if len(ans) == 1: print(*ans) else: print("-1")