{-# LANGUAGE FlexibleContexts #-}

import Control.Monad
import Control.Monad.ST
import Control.Applicative
import Data.List
import Data.Array
import Data.Array.ST
import Data.Maybe
import Data.Bits
import Data.Ord
import Data.Ratio
import Data.Int
import Data.Char
import qualified Data.ByteString.Char8 as BS
import qualified Data.Set as Set
import Data.STRef
import Text.Printf
import Debug.Trace
import Numeric

modifyArray arr i f = readArray arr i >>= \x -> writeArray arr i (f x)

listToTuple2 [a,b] = (a,b)
listToTuple3 [a,b,c] = (a,b,c)
listToTuple4 [a,b,c,d] = (a,b,c,d)

getWords = getLine >>= return . words

readIntBS = fst . fromJust . BS.readInt

for = flip map


main :: IO ()
main = do
  (n,m) <- listToTuple2 . map read . words <$> getLine :: IO (Int,Int)
  edges <- map ((\(a,b,c) -> (read a, read b, read c)) . listToTuple3 . words) . lines <$> getContents :: IO [(Int,Int,Int64)]

  let a = negate $ bellman_ford (1,n) (map (\(a,b,c) -> (a,b,-c)) edges) 1 n

  putStrLn $ if a == inf then "inf" else show a
  


inf = 10^10 :: Int64

type Node = Int
type Cost = Int64
type Edge = (Node, Node, Cost)

bellman_ford :: (Node,Node) -> [Edge] -> Node -> Node -> Cost
bellman_ford bound@(lower,upper) edges src dst = runST $ do
  arr <- newArray bound inf :: ST s (STUArray s Node Cost)
  negcycle <- newSTRef False :: ST s (STRef s Bool)

  writeArray arr src 0
  forM_ [1..(upper-lower+1)] $ \i -> do
    forM_ edges $ \(s,e,c) -> do
      x <- (+c) <$> readArray arr s
      y <- readArray arr e
      when (x < y) $ do
        writeArray arr e x
          
  forM_ [1..(upper-lower+1)] $ \i -> do
    forM_ edges $ \(s,e,c) -> do
      x <- (+c) <$> readArray arr s
      y <- readArray arr e
      when (x < y) $ do
        writeArray arr e x
        when (e == dst) $ do
          writeSTRef negcycle True

  ncExists <- readSTRef negcycle
  if ncExists then
    return (-inf)
    else
    readArray arr dst
  
