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

apply n f x = foldr ($) x (replicate n f)

main = do
 [n,_] <- map read . words <$> getLine
 abcs <- map (map read . words) . lines <$> getContents
 putStrLn $ maybe "inf" show (scoreAttack n abcs)
 
scoreAttack n abcs = do 
 let gf = apply n (move abcs) (M.singleton 1 0)
 let gs = apply n (move abcs) gf
 guard (gf!n == gs!n)
 return (gf!n)
 
move abcs g = foldr (\[a,b,c] acc -> if M.member a g then M.insertWith max b ((g!a) + c) acc else acc) g abcs
