n = int(input()) a = list(map(int,input().split())) res = [] for i in range(12): b = [(j + i) % 12 for j in (0, 2, 4, 5, 7, 9, 11)] ok = True for j in a: if j not in b: ok = False break if ok: res.append(i) if len(res) == 1: print(res[0]) else: print(-1)