n,m=io.read("*n","*n")
d={}
for i=1,n do
	d[i]={}
	d[i][i]=0
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
		c=d[i][k]
		if c then
		for j,v in pairs(d[k]) do
			a=c+v
			b=d[i][j]
			if b==nil or b<a then d[i][j]=a end
		end
		end
	end
end

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