import Control.Monad
import Data.Array
main = do
  [n,m] <- map read . words <$> getLine
  e <- replicateM m $ map read . words <$> getLine
  let x = listArray (1,n) $ 0 : repeat (-(10^9*m+1))
      y = iterate (\x -> accum max x [(b,x!a+c) | [a,b,c] <- e]) x !! n
      z = iterate (\x -> accum max x [(b,x!a+c) | [a,b,c] <- e]) y !! n
  putStrLn $ if y!n==z!n then show $ y!n else "inf"