# a,b,c,d = map(int,input().split()) # if a < b and c > d: # print("YES") # else:print("NO") # n,h = map(int,input().split()) # a = list(map(int,input().split())) # for i in range(n): # a[i] += h # print(*a) n = int(input()) t = list(map(int,input().split())) comb = [] for i in range(12): u = [] u.append(i) u.append((i+2)%12) u.append((i+4)%12) u.append((i+5)%12) u.append((i+7)%12) u.append((i+9)%12) u.append((i+11)%12) comb.append(u) ans = [] for i in range(12): tar = comb[i] flag = True for j in t: if j not in tar: flag = False if flag: ans.append(i) if len(ans) == 1: print(ans[0]) else: print(-1)