{-# LANGUAGE FlexibleContexts #-}

import Control.Monad
import Control.Monad.ST
import Data.Array.ST
import qualified Data.ByteString.Char8 as C
import Data.Int
import Data.List
import Data.Maybe

main = sol <$> get >>= putStrLn

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

sol ([n,_]:es) = maybe "inf" (show . negate) $ bellman_ford n wes
  where
  wes = fmap (\[u,v,c] -> (u,v,fromIntegral (-c))) es :: [(Int, Int, Int64)]

inf = 10^18 :: Int64

bellman_ford n es = runST $ do
  d <- newArray (1,n) inf :: ST s (STUArray s Int Int64)
  writeArray d 1 0
  forM_ [1..n-1] $ \_ -> f es d
  c <- readArray d n
  forM_ [1..n] $ \_ -> f es d
  c' <- readArray d n
  return $ if c' < c then Nothing else Just c

f es d = forM_ es $ \(u,v,c) -> do
  x <- readArray d u
  y <- readArray d v
  when (x<inf && x+c<y) $ do
    writeArray d v (x+c)