N = int(input()) tigau = [1, 3, 6, 8, 10] T = list(map(int, input().split())) cho = set() for D in range(12): ok = True for t in tigau: if (D + t) % 12 in T: ok = False break if ok: cho.add(D) if len(cho) == 1: for i in cho: print(i) else: print(-1)