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