import Control.Monad
import Data.List

solve :: Int->[(Int,Int,Int)]->[(Int,Int,Int)]->Int
solve n list1 list2
    | hasall   = sum $ map (\(a,b,d)->d`div`100-1) list1
    | otherwise = head $ sort $ map (\l->solve n (l:list1) (delete l list2)) list2
        where la = map (\(a,b,d)->a) list1
              lb = map (\(a,b,d)->b) list1
              hasall = and $ map (\x->elem x (la++lb)) [0..(n-1)]

readInput :: IO ()
readInput = do
    ln <- getLine
    let n = read ln :: Int
    if n==0 then return () else return =<< readInput' n

readInput' :: Int->IO ()
readInput' n = do
    lm <- getLine
    let m = read lm :: Int
    str <- replicateM m getLine
    let myread s = read ("("++s++")")::(Int,Int,Int)
    let list = map myread str
    print (solve n [] list)
    return =<< readInput

main :: IO ()
main = do
    readInput