val INF = Long.MAX_VALUE

data class Edge(val a: Int, val b: Int, val c: Long)

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map(String::toInt)

    val edges = Array(M) {
        val (a, b, c) = readLine()!!.split(" ")
        Edge(a.toInt() - 1, b.toInt() - 1, -c.toLong())
    }

    val dist = LongArray(N) { INF }

    dist[0] = 0

    for (loop in 0..(N - 2)) {
        (0..(M - 1))
                .map { edges[it] }
                .filter { dist[it.a] != INF && dist[it.b] > dist[it.a] + it.c }
                .forEach { dist[it.b] = dist[it.a] + it.c }
    }

    val ans = dist[N - 1]

    val negative = BooleanArray(N) { false }

    for (loop in 0..N - 1) {
        for (i in 0..M - 1) {
            val edge = edges[i]
            if (dist[edge.a] == INF) continue

            if (dist[edge.b] > dist[edge.a] + edge.c) {
                dist[edge.b] = dist[edge.a] + edge.c
                negative[edge.b] = true
            }

            if (negative[edge.a]) {
                negative[edge.b] = true
            }
        }
    }

    if (negative[N - 1]) {
        println("inf")
    } else {
        println(-ans)
    }
}