unittest
{
	assert( [ "5 3", "3 1 4", "1 5 9", "2 6 5", "3 5 8", "9 7 9" ].parse.expand.solve == 56 );
	assert( [ "5 3", "1 -2 3", "-4 5 -6", "7 -8 -9", "-10 11 -12", "13 -14 15" ].parse.expand.solve == 54 );
	assert( [ "10 5", "10 -80 21", "23 8 38", "-94 28 11", "-26 -2 18", "-69 72 79", "-26 -86 -54", "-72 -50 59", "21 65 -32", "40 -94 87", "-62 18 82" ].parse.expand.solve == 638 );
	assert( [ "3 2", "2000000000 -9000000000 4000000000", "7000000000 -5000000000 3000000000", "6000000000 -1000000000 8000000000" ].parse.expand.solve == 30000000000 );
}



import std.algorithm;
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 xyzs = new long[][]( nm[ 0 ], 3 );
	foreach( ref xyz; xyzs )
	{
		input.popFront;
		xyz = input.front.split.to!( long[] );
	}
	return tuple( nm[ 1 ], xyzs );
}

auto solve( long m, long[][] xyzs )
{
	auto ans = 0L;
	
	// 各評価項目ごとに正方向or負方向をとった結果を計算
	auto bm = 1 << xyzs[ 0 ].length;
	for( auto b = 0; b < bm; b++ )
	{
		auto ts = new long[]( xyzs.length );
		foreach( ref t, xyz; lockstep( ts, xyzs ) )
		{
			auto bb = b;
			foreach( v; xyz )
			{
				if( bb & 1 ) t += v;
				else         t -= v;
				bb >>= 1;
			}
		}
		ts.sort!( ( a, b ) => b < a );
		ans = max( ans, ts.take( m ).sum );
	}
	
	return ans;
}
