import qualified Data.IntMap as M
import Data.Maybe (fromJust)
import Control.Monad
import Data.Array.IO
import Data.List

main = do
  [n, m] <- map read . words <$> getLine :: IO [Int]
  input <- (\[x, y, z] -> zip3 x y z) . transpose . map (map read . words) . lines <$> getContents :: IO [(Int, Int, Int)]
  weight <- newArray (0, n) 0 :: IO (IOUArray Int Int)
  mark <- newArray (1, n) False :: IO (IOUArray Int Bool)
  let graph = foldl makeGraph M.empty input
      neighbor = M.toList . fromJust $ M.lookup 1 graph
  writeArray mark 1 True
  foldM (search graph weight 1 n) mark neighbor
  inf <- readArray weight 0
  ans <- readArray weight n
  if inf == -1 then putStrLn "inf"
               else print ans

type Weight = Int
type Vertex = (Int, Weight)
--key:頂点番号, value:隣接点集合
type Graph = M.IntMap Neighbor
--key:ある点の隣接点の頂点番号, value:辺の重さ
type Neighbor = M.IntMap Weight

--隣接リスト
makeGraph :: Graph -> (Int, Int, Int) -> Graph
makeGraph graph (x, y, z) =
  let nX = M.lookup x graph
  in if nX == Nothing
       then M.insert x (addNeighbor (y, z) M.empty) graph
       else M.insert x (addNeighbor (y, z) $ fromJust nX) graph

addNeighbor :: (Int, Int) -> Neighbor -> Neighbor
addNeighbor (i, weight) ne = M.insert i weight ne

--DFS : 前pre 現在i
search :: Graph -> IOUArray Int Int -> Int -> Int -> IOUArray Int Bool -> Vertex -> IO (IOUArray Int Bool)
search graph weight pre dst mark (i, w) = do
  isMark <- readArray mark i
  case isMark of
    True -> do
      if i == dst
        then do
          wBest <- readArray weight i
          wSum <- readArray weight pre
          writeArray weight i $ max (wSum + w) wBest
          let ne = M.lookup i graph
          if ne == Nothing
            then return mark
            else do
              let neList = M.toList . fromJust $ ne
              return =<< foldM (search graph weight i dst) mark neList
        else do
          writeArray weight 0 (-1)
          return mark
    False -> do
      writeArray mark i True
      wSum <- readArray weight pre
      writeArray weight i (wSum + w)
      let ne = M.lookup i graph
      if ne == Nothing
        then return mark
        else do
          let neList = M.toList . fromJust $ ne
          return =<< foldM (search graph weight i dst) mark neList
