{-# LANGUAGE RankNTypes #-}
import Control.Arrow
import Control.Monad
import Data.List
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as MV
import Control.Monad.ST

main :: IO ()
main = readLine >>= main'
    where
        main' [n, m] = readContents m >>= printRes . solve n
        printRes = maybe (putStrLn "inf") print

solve :: Int -> [[Int]] -> Maybe Int
solve n abcs = bellmanFord (n - 1) graph 0 (n - 1) >>= next . edit
    where
        next res = bellmanFord (2 * n - 1) graph 0 (n - 1) >>= check res . edit
        check a b
            | a == b = return a
            | otherwise = Nothing
        edit = negate . fst
        graph = Graph n es inf
        es = map mf abcs
        mf [a, b, c] = Edge (a - 1) (b - 1) (-c)
        inf = 10 ^ 12 + 1

data Graph a = Graph Int [Edge a] a
data Edge a = Edge Int Int a

bellmanFord :: (Ord a, Num a) => Int -> Graph a -> Int -> Int -> Maybe (a, [Int])
bellmanFord m gr@(Graph n es inf) s t = runST (initialize inf >>= loop inf m es)
    where
        initialize :: (Ord a, Num a) => forall s. a -> ST s (MV.STVector s (a, Int))
        initialize inf = MV.replicate n (inf, n) >>= write
            where
                write ds = ds <$ MV.unsafeWrite ds s (fromInteger 0, s)

        loop :: (Ord a, Num a) => forall s. a -> Int -> [Edge a] -> MV.STVector s (a, Int) -> ST s (Maybe (a, [Int]))
        loop inf c es ds = foldM ff False es >>= check
            where
                ff acc (Edge a b c) = rds >>= edit
                    where
                        rds = (,) <$> rf a <*> rf b
                        rf i = fst <$> MV.unsafeRead ds i
                        edit (al, bl)
                            | al >= inf = return acc 
                            | bl > al + c = True <$ (MV.unsafeWrite ds b (al + c, a))
                            | otherwise = return acc 
                check acc 
                    | acc && c > 0 = loop inf (c - 1) es ds 
                    | acc = return Nothing
                    | otherwise = return . calcResult <$> V.unsafeFreeze ds

        calcResult :: V.Vector (a, Int) -> (a, [Int])
        calcResult ds = (fst $ ds V.! t, ploop [] t)
            where
                ploop ps v 
                    | v == s = s : ps
                    | otherwise = ploop (v : ps) . snd $ ds V.! v

readLine :: IO [Int]
readLine = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

readContents :: Int -> IO [[Int]]
readContents = flip replicateM readLine