import Data.Array
import qualified Data.ByteString.Char8 as C
import qualified Data.IntSet as S
import Data.List
import qualified Data.Map.Strict as M
import Data.Maybe

main = sol <$> get >>= put

get = fmap (unfoldr (C.readInt . C.dropWhile (==' '))) . C.lines <$> C.getContents  

put = putStrLn . maybe "inf" show

sol :: [[Int]] -> Maybe Int
sol ([n,m]:es) = if circuit g S.empty 1 then Nothing else Just c
  where
  g = accumArray (flip (:)) [] (1,n) $ fmap (\[u,v,c] -> (u,v)) es
  cs = M.fromList $ fmap (\[u,v,c] -> ((u,v),c)) es
  cost p = sum . fmap (cs M.!) $ zip p (tail p)
  c = maximum . fmap cost $ allpaths g 1 n

circuit g s = any (\u -> u `S.member` s || circuit g (S.insert u s) u) . (g!)

allpaths g u v
  | u == v = [[v]]
  | otherwise = concatMap (fmap (u:) . flip (allpaths g) v) (g!u)