import java.util.*

fun main(args: Array<String>) {
	val (n, m) = readLine()!!.split(" ").map({ it -> it.toInt() })
	val graph = WeightedDirectedGraph(n)
	for (i in 1..m) {
		val (a, b, c) = readLine()!!.split(" ").map({ it -> it.toInt() })
		graph.addEdge(a - 1, b - 1, (-c).toLong())
	}
	val ans = bellmanFord(0, n - 1, graph)
	if (ans == null) {
		println("inf")
	} else {
		println(-ans)
	}
}

class WeightedDirectedGraph(n: Int) {
	val len = n
	val edges = Array<MutableList<Pair<Int, Long>>>(n) { mutableListOf() }
	fun addEdge(from: Int, to: Int, cost: Long) {
		this.edges[from].add(Pair(to, cost))
	}
}

fun bellmanFord(src: Int, snk: Int, graph: WeightedDirectedGraph): Long? {
	val costs = LongArray(graph.len) { Long.MAX_VALUE }
	costs[src] = 0L
	for (i in 1..(graph.len - 1)) {
		for (j in 0..(graph.len - 1)) {
			if (costs[j] == Long.MAX_VALUE) {
				continue
			}
			for (p in graph.edges[j]) {
				val newCost = costs[j] + p.second
				costs[p.first] = Math.min(newCost, costs[p.first])
			}
		}
	}
	for (i in 1..graph.len) {
		for (j in 0..(graph.len - 1)) {
			if (costs[j] == Long.MAX_VALUE) {
				continue
			}
			for (p in graph.edges[j]) {
				val newCost = costs[j] + p.second
				if (newCost < costs[p.first]) {
					costs[p.first] = newCost
					if (p.first == snk) {
						return null
					}
				}
			}
		}
	}
	return costs[snk]
}