object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m = sc.nextInt()
  val e = List.fill(m)((sc.nextInt()-1, sc.nextInt()-1, -sc.nextInt()))

  def shortestPath(s: Int, n: Int, edges: Seq[(Int, Int, Int)]): Array[Long] = {
    val adj = Array.fill(n)(List[Int]())
    for ((u, v, _) <- edges) {
      adj(u) ::= v
    }

    val sp = Array.fill(n)(Long.MaxValue)
    sp(s) = 0

    for {
      _ <- 1 until n
      (u, v, l) <- edges if sp(u) != Long.MaxValue
    } {
      sp(v) = sp(v).min(sp(u) + l)
    }

    var visited = Set[Int]()
    val stack = Stack[Int]()
    for ((u, v, l) <- edges if sp(u) != Long.MaxValue) {
      if (sp(v) > sp(u) + l) {
        visited += v
        stack.push(v)
      }
    }

    while (stack.nonEmpty) {
      val u = stack.pop()
      for (v <- adj(u) if !visited(v)) {
        visited += v
        stack.push(v)
      }
    }

    for (u <- visited) {
      sp(u) = Long.MinValue
    }

    sp
  }

  val sp = shortestPath(0, n, e)
  println(if (sp(n-1) == Long.MinValue) "inf" else -sp(n-1))
}
