import Data.List
import Data.IntMap ((!))
import qualified Data.IntMap as M
import Control.Monad

main = do
 [n,m] <- map read . words <$> getLine
 abcs <- map (map read . words) . lines <$> getContents
 putStrLn $ maybe "inf" show (scoreAttack n abcs)

scoreAttack n abcs = do 
 let ad = foldr (move abcs) (M.singleton 1 0) [1..1000]
 let mn = foldr (move abcs) ad [1..100]
 guard (ad!n == mn!n)
 return (ad!n)

move abcs i im = foldr (\[a,b,c] -> M.insertWith max b ((im!a) + c)) im from
 where
  ks = M.keys im
  from = filter ((flip elem ks) . head) abcs