import java.util.*
import java.math.*
import java.lang.Math.*

val readString: ()->String = {readLine()!!}
val readInt: ()->Int = {readLine()!!.toInt()}
val readLong: ()->Long = {readLine()!!.toLong()}
val readIntArray: ()->IntArray = {readLine()!!.split(' ').map{it.toInt()}.toIntArray()}
val readLongArray: ()->LongArray = {readLine()!!.split(' ').map{it.toLong()}.toLongArray()}
val errPrintln: (String)->Unit = {msg -> System.err.println(msg)}
val MOD = 1e9.toLong()+7
val INF = Int.MAX_VALUE/2
val LINF = Long.MAX_VALUE/2
data class IntPair(val first: Int, val second: Int)
data class To(val idx: Int, val cost: Long)


class Bellman(val eg: Array<ArrayList<To>>, val start: Int) {
    private var dist = LongArray(0)

    var hasCycle = false
    private set

    init {
        val N = eg.size

        dist = LongArray(N){-LINF}
        dist[start] = 0L

        for (i in 0 until N) {
            var updating = false
            for (x in 0 until N)  {
                for (t in eg[x]) {
                    val y = t.idx

                    if (dist[x] + t.cost > dist[y]) {
                        dist[y] = dist[x] + t.cost
                        updating = true
                    }
                }
            }
            if (!updating) break
        }

        hasCycle = calcCycle()
    }


    private fun calcCycle(): Boolean {
        val N = eg.size
        val ndst = dist.clone()
        for (i in 0 until N) {
            var updating = false
            for (x in 0 until N)  {
                for (t in eg[x]) {
                    val y = t.idx
                    if (ndst[x] + t.cost > ndst[y]) {
                        ndst[y] = ndst[x] + t.cost
                        updating = true
                    }
                }
            }
            if (!updating) break
        }

        return ndst[N-1] != dist[N-1]
    }


    fun distance(i: Int): Long {
        return if(hasCycle) LINF else dist[i]
    }
}


fun solve(eg: Array<ArrayList<To>>): Long {
    val N = eg.size

    val bm = Bellman(eg, 0)

    return bm.distance(N-1)
}


fun main(args: Array<String>) {
    val (N, M) = readIntArray()
    val eg = Array(N){ArrayList<To>()}
    for (i in 0 until M) {
        var (a, b, c) = readLongArray()
        a--;b--;
        eg[a.toInt()].add(To(b.toInt(), c))  // 有向グラフ
    }

    val ans = solve(eg)

    if (ans == LINF) println("inf")
    else println(ans)
}
