import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)

  val n = sc.nextInt(); val m = sc.nextInt()
  val graph = new Array[List[(Int, Int)]](n + 1)
  for(i <- 0 to n)
    graph(i) = List()

  for(i <- 1 to m){
    val a = sc.nextInt(); val b = sc.nextInt(); val c = sc.nextInt()
    graph(a) = (b, c) :: graph(a)
  }


  // main process
  var tmp = 0L
  var flag = false
  val dp: Array[Long] = Array.fill(n+1)(-1e18.toLong)
  dp(1) = 0

  for(i <- 1 to 2 * (n-1)) {
    for(a <- 1 to n) {
      for((b, c) <- graph(a)){
        dp(b) = Math.max(dp(b), dp(a) + c)
      }
    }

    if(i == n-1)
      tmp = dp(n)
    else if(i == 2 * (n-1) && tmp < dp(n))
      flag = true
  }
  

  if(flag)
    println("inf")
  else
    println(dp(n))
}
