n = int(input()) *t, = map(int,input().split()) s = [0,2,4,5,7,9,11] v = [] for i in range(12): if all((j-i)%12 in s for j in t): v.append(i) print(v[0] if len(v)==1 else -1)