unittest
{
	assert( [ "3 3", "1 2 4", "2 3 3", "1 3 5" ].parse.expand.solve == "7" );
	assert( [ "2 2", "1 2 1", "2 1 1" ].parse.expand.solve == "inf" );
	assert( [ "6 5", "1 2 -1000000000", "2 3 -1000000000", "3 4 -1000000000", "4 5 -1000000000", "5 6 -1000000000" ].parse.expand.solve == "-5000000000" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nm = input.front.split.to!( long[] );
	auto abcs = new long[ 3 ][ nm[ 1 ] ];
	foreach( ref abc; abcs )
	{
		input.popFront;
		abc = input.front.split.to!( long[] );
		abc[ 0 .. 2 ] -= 1;
		abc[ 2 ] = -abc[ 2 ];
	}
	return tuple( nm[ 0 ], abcs );
}

auto solve( long n, long[ 3 ][] abcs )
{
	auto ds = bellmanford( n, abcs, 0 );
	if( ds[ $ - 1 ] == long.min ) return "inf";
	else                          return ( -ds[ $ - 1 ] ).to!( string );
}

// 正負の重み付きグラフの始点指定最短経路探索（ベルマンフォード法）
auto bellmanford( long n, long[ 3 ][] es, long s )
{
	auto ds = new long[ n ];
	ds[] = long.max;
	ds[ s ] = 0;
	
	foreach( c; 0L .. n * 2 )
	{
		auto r = false;
		foreach( i, e; es )
		{
			auto td = ( ds[ e[ 0 ] ] != long.min ) ? ds[ e[ 0 ] ] + e[ 2 ] : long.min;
			if( ds[ e[ 0 ] ] == long.max || ds[ e[ 1 ] ] <= td ) continue;
			ds[ e[ 1 ] ] = ( c < n ) ? td : long.min;		// 負閉路があったらminで塗りつぶす
			r = true;
		}
		if( !r ) break;
	}
	return ds;
}
