require "set" N = gets.to_i T = gets.split.map(&:to_i) cands = (0..11).filter { |x| Set.new(T).subset? Set.new([x, x + 2, x + 4, x + 5, x + 7, x + 9, x + 11].map{_1 % 12}) } puts cands.empty? || cands.size > 1 ? -1 : cands[0]