import qualified Data.Vector as V
import Control.Monad
import Data.List (foldl')

data S = Ninf | V Int deriving (Eq,Show)

unpack :: S -> Int
unpack (V x) = x

u :: V.Vector S -> [Int] -> V.Vector S
u arr [a,b,c] = V.force $ case (arr V.! a,arr V.! b) of
  (Ninf,_) -> arr
  (V x,Ninf) -> arr V.// [(b,V $ x+c)]
  (V x,V y) -> if x+c >= y then arr V.// [(b,V $ x+c)] else arr

proc :: [[Int]] -> V.Vector S -> V.Vector S
proc es ia = foldl' u ia es

iter :: Int -> (a -> a) -> a -> a
iter 0 f x = x
iter n f x = f $ iter (n-1) f x

main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine
  es <- replicateM m $ map read . words <$> getLine
  let
    es' = map (\[a,b,c] -> [a-1,b-1,c]) es
    a0 = V.fromListN n $ V 0 : repeat Ninf
    a1 = iter (n+2) (proc es) a0
    a2 = iter 2 (proc es) a1
    n' = n-1
  if a1 V.! n' /= a2 V.! n'
    then putStrLn "inf"
    else print $ unpack $ a1 V.! n'