MOD = 12 def func(a): ret = set() for i in [0, 2, 4, 5, 7, 9, 11]: ret.add((a + i) % 12) return ret N = int(input()) T = set(map(int, input().split())) ans = -1 for i in range(12): # print(func(i)) # if i == 2: # print("T <= func(i) : ", T <= func(i)) if T <= func(i): if ans == -1: ans = i else: # print("ans =", ans) ans = -1 # print("func(i) =", func(i)) break print(ans)