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

infinite = maxBound :: Int

main = do
  [n, m] <- map read . words <$> getLine :: IO [Int]
  input <- (\[x, y, z] -> zip3 x y $ map negate z) . transpose . map (map read . words) . lines <$> getContents :: IO [(Int, Int, Int)]
  weight <- newArray (0, n) infinite :: IO (IOUArray Int Int)
  let graph = foldl makeGraph M.empty input
      index = [(i, v) | i <- [1..n], v <- [1..n]]
  writeArray weight 0 0
  writeArray weight 1 0
  foldM (bellmanFord graph n) weight index
  inf <- readArray weight 0
  ans <- readArray weight n
  if inf == -1 then putStrLn "inf"
               else print $ negate ans

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

--隣接リスト
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

bellmanFord :: Graph -> Int -> Memo -> (Int, Int) -> IO Memo
bellmanFord graph n weight (i, v) = do
  b <- readArray weight 0
  case b of
    0 -> do
      let neMaybe = M.lookup v graph
      case neMaybe of
        Nothing -> do
          return weight
        _ -> do
          let neighbors = M.toList $ fromJust neMaybe
          foldM bf' weight neighbors
          return weight
    _ -> do
      return weight
    where bf' weight (e, w) = do
            updatable <- readArray weight 0
            case updatable of
              0 -> do
                distE <- readArray weight e
                distV <- readArray weight v
                let isUpdate = distE > distV + w
                    dist = if isUpdate then distV + w
                                       else distE
                    isClosed = if isUpdate && i == n
                                 then (-1) else 0
                writeArray weight e dist
                writeArray weight 0 isClosed
                return weight
              _ -> do
                return weight
