T={*map(int, open(0).read().split()[1:])};print((-1,*(ans:=[x for x in range(12)if T<={(x+y)%12for y in(0,2,4,5,7,9,11)}]))[len(ans)==1])