import java.math.*;
// import java.util.*;
data class Edge(val from:Int,val to:Int,val cost:Long)

object MainKt {
  @JvmStatic fun main(args:Array<String>) {
   val (N,M)=readLine()!!.split(" ").map(String::toInt)
   val graph=(1..M).map{
     val (a,b,c)=readLine()!!.split(" ").map(String::toLong)
     Edge(a.toInt(),b.toInt(),-c)
   }
   val inf=1000000001L*N*M
   var dist=Array(N) {inf}
  //  var is_closed=false


   dist[0]=0
   var dist_n = 0L
   for(j in 0.until(N)) {
      for(node in graph) {
        val (u,v,c)=node
        
        if(dist[u-1] +c < dist[v-1]) {
          dist[v-1]=dist[u-1]+c
        }
      }
      if(j==N-1) {
            dist_n=dist[N-1]
          }
   }
   for(j in 0.until(N)) {
      for(node in graph) {
        val (u,v,c)=node
        
        if(dist[u-1] +c < dist[v-1]) {
          dist[v-1]=dist[u-1]+c
        }
      }
   }  
   println(if(dist_n==dist[N-1]) {-dist[N-1]} else {"inf"} )
  }
}
