N = int(input()) T = list(map(int,input().split())) cnt = 0 ans = -1 for i in range(12): d = [i%12, (i+2)%12, (i+4)%12, (i+5)%12, (i+7)%12, (i+9)%12, (i+11)%12] f = True for t in T: if t not in d: f = False if f: cnt += 1 ans = i if cnt == 1: print(ans) else: print(-1)