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 )
{
	if( m == 0 ) return 0;
	
	// 各評価項目ごとに正方向or負方向をとった結果を計算
	auto ans = 0L;
	ans = max( ans, solve2( [  1,  1,  1 ], m, xyzs ) );
	ans = max( ans, solve2( [  1,  1, -1 ], m, xyzs ) );
	ans = max( ans, solve2( [  1, -1,  1 ], m, xyzs ) );
	ans = max( ans, solve2( [  1, -1, -1 ], m, xyzs ) );
	ans = max( ans, solve2( [ -1,  1,  1 ], m, xyzs ) );
	ans = max( ans, solve2( [ -1,  1, -1 ], m, xyzs ) );
	ans = max( ans, solve2( [ -1, -1,  1 ], m, xyzs ) );
	ans = max( ans, solve2( [ -1, -1, -1 ], m, xyzs ) );
	return ans;
}

auto solve2( long[] ss, long m, long[][] xyzs )
{
	auto mxyz = solve3( ss, m, xyzs );
	return mxyz[ 0 ] * ss[ 0 ] + mxyz[ 1 ] * ss[ 1 ] + mxyz[ 2 ] * ss[ 2 ];
}

long[] solve3( long[] ss, long m, long[][] xyzs )
{
	m--;
	auto mxyz = [ 0L, 0L, 0L ];
	auto ma = 0L;
	foreach( i, xyz; xyzs[ 0 .. $ - m ] )
	{
		if( 0 < m )
		{
			auto r = solve3( ss, m, xyzs[ i + 1 .. $ ] );
			xyz = [ xyz[ 0 ] + r[ 0 ], xyz[ 1 ] + r[ 1 ], xyz[ 2 ] + r[ 2 ] ];
		}
		
		auto ra = xyz[ 0 ] * ss[ 0 ] + xyz[ 1 ] * ss[ 1 ] + xyz[ 2 ] * ss[ 2 ];
		if( ma < ra )
		{
			mxyz = xyz;
			ma = ra;
		}
	}
	return mxyz;
}
