import collections N = int(input()) T = list(map(int, input().split())) CT = collections.Counter(T) L = [0,2,4,5,7,9,11] ans = -1 for i in range(12): D = [] for l in L: D.append((i+l)%12) if not(CT - collections.Counter(D)): if ans==-1: ans=i else: print(-1) exit() print(ans)