{-# LANGUAGE FlexibleContexts #-}

import Control.Monad
import Data.STRef
import Data.Array.MArray
import Data.Array.Unboxed
import Data.Array.ST
import Control.Monad.ST
{--
data Score = Inf | Fin Int deriving (Eq,Show)
instance Ord Score where
  compare Inf     Inf = EQ
  compare (Fin _) Inf = LT
  compare Inf (Fin _) = GT
  compare (Fin a) (Fin b)= compare a b

plus::Score -> Score -> Score
plus Inf _ = Inf
plus _ Inf = Inf
plus (Fin a) (Fin b) = Fin (a+b)

--type W_D_graph = Array (Int,Int) Score
--graph implimentation changed: (a,b,c):a to b wieght c
--}
type Graph = [(Int,Int,Int)]



bellman_ford::Graph -> Int -> Int -> UArray Int Int
bellman_ford gr size st = runSTUArray $ do
  tab<- newArray (1,size) maxBound
  writeArray tab st 0
  flag_tab<- newArray (1,size) True
  flagptr<-newSTRef flag_tab
  tab_ptr<-newSTRef tab
  gr_ptr <-newSTRef gr
  forM_ [1..(size-1)] (propagate gr_ptr tab_ptr)
  forM_ [1..size    ] (propagate' gr_ptr tab_ptr flagptr)
  forM_ [1..size    ] (rewrite tab_ptr flagptr)
  return tab
      where rewrite tab_ptr flagptr i = do
                                        tab<-readSTRef tab_ptr
                                        flags<-readSTRef flagptr
                                        i_res<-readArray tab i
                                        i_flag<-readArray flags i
                                        writeArray tab i (if i_flag then i_res else minBound)

{--
  ar<-freeze tab
  let result =listArray (1,size) $(map (\(x,b)->if b then Just x else Nothing) (elems ar))
  return result
--}

propagate::STRef s Graph ->STRef s (STUArray s Int Int)  -> Int -> (ST s ())
propagate gr_ptr tab_ptr _= do
  gr<-readSTRef gr_ptr
  forM_ gr one_edge_update
        where one_edge_update (a,b,c) = do
                              tab<-readSTRef tab_ptr
                              tab_a<-readArray tab a
                              tab_b<-readArray tab b
                              let next_b = min (tab_a+c) tab_b
                              writeArray tab b next_b

propagate'::STRef s Graph ->STRef s (STUArray s Int Int) -> STRef s (STUArray s Int Bool) -> Int -> (ST s ())
propagate' gr_ptr tab_ptr flagptr _= do
  gr<-readSTRef gr_ptr
  forM_ gr one_edge_update
        where one_edge_update (a,b,c) = do
                              tab<-readSTRef tab_ptr
                              tab_a<-readArray tab a
                              tab_b<-readArray tab b
                              let next_b = min (tab_a+c) tab_b
                              let next_flag = (next_b == tab_b)
                              writeArray tab b next_b
                              flags<-readSTRef flagptr
                              writeArray flags b next_flag


n_get::Int ->IO [(Int,Int,Int)]
n_get 0 =return []
n_get n =do
  d<-getLine
  let a:b:w:[]= map read (words d)
  rest <- n_get (n-1)
  return ((a,b,(-w)):rest)

main::IO()
main=do
  nmc<-getLine
  let n:m:[]=map read (words nmc)::[Int]
  gr<-n_get m
  let ans = (bellman_ford gr n 1)!n
  if ans==minBound then do putStr ("inf"++"\n")
                   else do print (-ans)