require 'set' def solve x = (0..11).filter do |d| Set.new(T).subset?(Set.new([d, d + 2, d + 4, d + 5, d + 7, d + 9, d + 11].map{_1 % 12})) end if x.size == 0 || x.size >= 2 then -1 else x[0] end end N = gets.to_i T = gets.split.map(&:to_i) puts solve