n = int(input()) x = list(map(int, input().split())) t = 0 for i in range(n): t |= 1 << x[i] def loop(i, acc): def check(o): return (t & (1 << ((i + o) % 12))) == 0 if i == 12: return acc if check(1) and check(3) and check(6) and check(8) and check(10): acc.append(i) return loop(i + 1, acc) res = loop(0, []) if len(res) == 1: print(res[0]) else: print(-1)