n = gets.to_i possibility = [true]*10 n.times do *a, r = gets.chomp.split a = a.map(&:to_i) if 'YES' == r 10.times do |i| next if a.include?(i) possibility[i] = false end next end a.each do |i| possibility[i] = false end end possibility.each.with_index do |p, i| next unless p puts i exit 0 end