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