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