n,m=io.read("*n","*n")
d={}
e=-1e15
for i=1,n do
	d[i]={}
	for j=1,n do
		d[i][j]=(i==j and 0 or e)
	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
		local c=d[i][k]
		if c~=e then
			for j=1,n do
				local f=d[k][j]
				if f~=e then
					local a=c+f
					local b=d[i][j]
					if b<a then d[i][j]=a end
				end
			end
		end
	end
end

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