def is_tone_notes(root: int) -> set[int]: return {(root + interval) % 12 for interval in (0, 2, 4, 5, 7, 9, 11)} def main(): N = int(input()) T = set(map(int, input().split())) tones = set() for root in range(12): if is_tone_notes(root).issuperset(T): tones.add(root) if len(tones) == 1: print(tones.pop()) else: print(-1) if __name__ == "__main__": main()