N = gets.to_i T = gets.split.map(&:to_i) cands = (0..11).select { |d| ham = [d, d + 2, d + 4, d + 5, d + 7, d + 9, d + 11].map { |v| v % 12 } (T - ham).empty? } if cands.size == 1 puts cands.first else puts -1 end