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