until (n = $<.gets.to_i).zero?
  m = $<.gets.to_i
  field = []
  Array.new(m) {$<.gets.split(",").map(&:to_i)}.each do |a, b, d|
    n = d / 100 - 1
    field += field.map {|spots, num| [(spots + [a, b]).uniq, num + n]}
    field << [[a, b], n]
  end
  puts field.select {|x| x.first.size == n}.sort_by {|x| x.last}.first.last
end
