n,m=io.read("*n","*n")
d={}
for i=1,n do
	d[i]={}
	for j=1,n do
		d[i][j]=(i==j and 0 or -1e15)
	end
end

for i=1,m do
	a,b,c=io.read("*n","*n","*n")
	d[a][b]=c
end
	
for k=1,n do
	for i=1,n do
		for j=1,n do
			d[i][j]=math.max(d[i][j],d[i][k]+d[k][j])
		end
	end
end

print(d[1][1]>0 and"inf"or d[1][n])