{-# LANGUAGE BangPatterns #-}

import Control.Monad
import qualified Data.ByteString.Char8 as C
import Data.Int
import Data.List
import Data.Maybe
import qualified Data.Vector.Unboxed as V

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)]

bellman_ford n wes = if ok then Just $ d1 `V.unsafeIndex` n else Nothing
  where
  ev = V.fromList $ wes
  d0 = V.replicate (n+1) inf V.// [(1, 0)]
  d1 = iterate (f ev) d0 !! (n-1)
  d2 = iterate (f ev) d1 !! n
  ok = d1 `V.unsafeIndex` n == d2 `V.unsafeIndex` n

inf = 10^18 :: Int64

f ev !d = V.unsafeAccumulate min d $ V.map upd ev
  where
  upd (u, v, c) = (v, min dv $ du+c)
    where
    du = d `V.unsafeIndex` u
    dv = d `V.unsafeIndex` v