#!/usr/bin/env python3 import sys input=sys.stdin.readline n=int(input()) arr=list(map(int,input().split())) scale=[0,2,4,5,7,9,11] cand=[] for i in range(12): s=set() for j in range(7): s.add((scale[j]+i)%12) for val in arr: if val not in s: break else: cand.append(i) if len(cand)==1: print(cand[0]) else: print(-1)