from copy import deepcopy N=int(input()) T=list(map(int,input().split())) G=[] for i in range(12): G.append([i,(i+2)%12,(i+4)%12,(i+5)%12,(i+7)%12,(i+9)%12,(i+11)%12]) for t in T: V=[] for H in G: if t in H: V.append(H) G=deepcopy(V) if len(G)!=1: print(-1) else: print(G[0][0])