until (n = $<.gets.to_i).zero?
  m = $<.gets.to_i
  table = Array.new(m) {$<.gets.split(",").map(&:to_i)}
  table.map! {|a, b, d| [a, b, d / 100 - 1]}
  
  min = Float::INFINITY
  (n - 2..m).each do |i|
    table.combination(i) do |paths|
      next unless paths.inject([]) {|a, path| a + path[0, 2]}.uniq.sort == [*0...n]
      n = paths.map{|path| path.last}.sum
      min = n if n < min
    end
  end
  puts min
end
