{-# LANGUAGE FlexibleContexts #-}

import Control.Monad
import Data.STRef
import Data.Array
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)

ADTomitted
--}



--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 -> Array Int (Maybe Int)
bellman_ford gr size st = runST $ do
  tab<- newArray (1,size) (maxBound,True)
  writeArray tab st (0,True)
  tab_ptr<-newSTRef tab
  forM_ [1..(size-1)] (propagate gr tab_ptr)
  forM_ [1..size    ] (propagate' gr tab_ptr)
  ar<-freeze tab
  let result =listArray (1,size) $(map (\(x,b)->if b then Just x else Nothing) (elems ar))
  return result

propagate::Graph ->STRef s (STArray s Int (Int,Bool))  -> Int -> (ST s ())
propagate gr tab_ptr _= do
  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 ((fst(tab_a))+c) (fst(tab_b))
                              writeArray tab b (next_b,snd tab_b)

propagate'::Graph ->STRef s (STArray s Int (Int,Bool))  -> Int -> (ST s ())
propagate' gr tab_ptr _= do
  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 ((fst(tab_a))+c) (fst(tab_b))
                              writeArray tab b (next_b,(next_b==(fst(tab_b)))&&(snd tab_a))



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
  case ans of
    Nothing -> do putStr ("inf"++"\n")
    Just x -> do print (-x)