import qualified Data.ByteString.Char8 as B
import Data.Maybe
import Control.Monad
import qualified Data.Array.IO as A

inf :: Int
inf = 100000000000

main :: IO ()
main = do
    [n, m] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    es <- replicateM m ((\[a,b,c]->(a,b,-c)) . map (fst . fromJust . B.readInt) . B.words <$> B.getLine)
    p <- A.newArray (1, n) inf :: IO (A.IOUArray Int Int)
    A.writeArray p 1 0
    s <- bellmanFord p es

    putStrLn =<< if isNothing s
        then return "inf"
        else show . negate <$> A.readArray (fromJust s) n

bellmanFord :: A.IOUArray Int Int
               -> [(Int, Int, Int)]
               -> IO (Maybe (A.IOUArray Int Int))
bellmanFord arr es = do
    (s,l) <- A.getBounds arr
    -- Bellman Ford
    forM_ [(i,t,ec)|i<-[s..l-1], (f,t,ec)<-es, f==i, f/=inf] $ \(i,t,edgeCost) -> do
        fromCost <- A.readArray arr i
        toCost <- A.readArray arr t
        when (toCost > fromCost+edgeCost) $ A.writeArray arr t (fromCost+edgeCost)

    -- 負閉路の検出
    fs <- forM [(i,t,ec)|i<-[l], (f,t,ec)<-es, f==i, f/=inf] $ \(i,t,edgeCost) -> do
        fromCost <- A.readArray arr i
        toCost <- A.readArray arr t
        return $ toCost > fromCost+edgeCost

    return $ if or fs then Nothing else Just arr
