n = int(input()) a = list(map(int,input().split())) for i in range(12): b = [(j + i) % 12 for j in (0, 2, 4, 5, 7, 9, 11)] ok = True for j in a: if j not in b: ok = False break if ok: print(i) exit(0) print(-1)