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