{-# 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)

type W_D_graph = Array (Int,Int) Score

bellman_ford::W_D_graph -> Int -> Int -> Array Int (Maybe Score)
bellman_ford gr size st = runST $ do
  tab<- newArray (1,size) (Inf,True)
  writeArray tab st (Fin 0,True)
  tab_ptr<-newSTRef tab
  gr_ptr <-newSTRef gr
  forM_ [1..(size-1)]$(propagate True  gr_ptr tab_ptr size)
  forM_ [1..size    ]$(propagate False gr_ptr tab_ptr size)
  ar<-freeze tab
  let result =listArray (1,size)(map (\(x,b)->if b then Just x else Nothing) (elems ar))
  return result

propagate::Bool -> (STRef s W_D_graph) ->STRef s (STArray s Int (Score,Bool)) -> Int -> Int -> (ST s ())
propagate flag gr_ptr tab_ptr size _= do
  tab<-readSTRef tab_ptr
  tab_im<-freeze tab
  forM_ [1..size] $(one_act tab_im)
        where one_act tab_im i = do
                              gr <-readSTRef gr_ptr
                              let next_i = minimum  $[plus (fst (tab_im!j)) (gr!(j,i))| j <- [1..size]]
                              tab'<-readSTRef tab_ptr
                              let next_flag = (next_i == (fst (tab_im!i)))
                              writeArray tab' i (next_i, (flag||next_flag) )


get_graph::Int -> [(Int,Int,Int)] -> W_D_graph
get_graph n dat = runSTArray $ do
  ar<-newArray ((1,1),(n,n)) Inf
  mapM_ (writer ar) dat
  mapM_ (diag   ar) [1..n]
  return ar
      where writer ar (a,b,w) = do
                        writeArray ar (a,b) (Fin (-w))
            diag   ar j       = do
                        writeArray ar (j,j) (Fin 0)

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]
  dat<-n_get m
  let gr = get_graph n dat
  let ans = (bellman_ford gr n 1)!n
  case ans of
    Nothing -> do putStr ("inf"++"\n")
    Just (Fin x) -> do print (-x)