import java.util.ArrayList

data class Edge(val from: Int, val to: Int, val weight: Long) {
    constructor(from: Long, to: Long, weight: Long) : this(from.toInt(), to.toInt(), weight)
}

class Graph(val n: Int) {
    val edges = Array(n) { ArrayList<Edge>() }
}

val INF = 1e+15.toLong()

fun bellmanFord(g: Graph, s: Int): Triple<Array<Long>, Array<Int>, Array<Boolean>> {
    val N = g.n
    val dist = Array(N) {INF}
    val prev = Array(N) {-1}

    dist[0] = 0

    for (k in 1 .. N) {
        for (v in 0 until N) {
            for (e in g.edges[v]) {
                if (dist[e.from] != INF && dist[e.to] > dist[e.from] + e.weight) {
                    dist[e.to] = dist[e.from] + e.weight
                    prev[e.to] = e.from
                }
            }
        }
    }

    val dist2 = dist.copyOf()
    for (k in 1 .. 3 * N) {
        for (v in 0 until N) {
            for (e in g.edges[v]) {
                if (dist2[e.from] != INF && dist2[e.to] > dist2[e.from] + e.weight) {
                    dist2[e.to] = dist2[e.from] + e.weight
                }
            }
        }
    }

    val affectedByNegativeLoop = Array(N) { idx -> dist[idx] != dist2[idx] }

    return Triple(dist, prev, affectedByNegativeLoop)
}

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

    for (i in 1 .. M) {
        val (a, b, c) = readLine()!!.split(" ").map {s -> s.toLong()}
        g.edges[(a - 1).toInt()].add(Edge(a - 1, b - 1, -c))
    }

    val (dist, prev, affectedByNegativeLoop) = bellmanFord(g, 0)

    if (affectedByNegativeLoop[N - 1]) {
        println("inf")
    } else {
        println(-dist[N - 1])
    }
}