import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N, *T = map(int, read().split()) T_se = set(T) ans = [] for D in range(12): D_se = set((D + x) % 12 for x in (0, 2, 4, 5, 7, 9, 11)) if T_se <= D_se: ans.append(D) if len(ans) == 1: print(ans[0]) else: print(-1)