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