unittest
{
	assert( [ "3 2", "1 7 2", "7 8 1", "8 12 1" ].parse.expand.solve == 2 );
	assert( [ "3 4", "1 3 2", "3 4 4", "1 4 3" ].parse.expand.solve == 3 );
	assert( [ "9 4", "56 60 4", "33 37 2", "89 90 3", "32 43 1", "67 68 3", "49 51 3", "31 32 3", "70 71 1", "11 12 3" ].parse.expand.solve == 2 );
}



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 nc = input.front.split.to!( long[] );
	auto stcs = new long[ 3 ][ nc[ 0 ] ];
	foreach( ref stc; stcs )
	{
		input.popFront;
		stc = input.front.split.to!( long[] );
	}
	return tuple( nc[ 1 ], stcs );
}

auto solve( long c, long[ 3 ][] stcs )
{
	// 同じチャンネルの連続する番組を一つにまとめる
	stcs.multiSort!( ( a, b ) => a[ 2 ] < b[ 2 ], ( a, b ) => a[ 0 ] < b[ 0 ] );
	auto dm = 0L;
	for( auto i = stcs.length.signed - 1; 0 < i; i-- )
	{
		dm = max( dm, stcs[ i ][ 1 ] );
		if( stcs[ i - 1 ][ 2 ] != stcs[ i ][ 2 ] || stcs[ i - 1 ][ 1 ] != stcs[ i ][ 0 ] ) continue;
		stcs[ i - 1 ][ 1 ] = stcs[ i ][ 1 ];
		stcs = stcs[ 0 .. i ] ~ stcs[ i + 1 .. $ ];
	}
	
	// 番組の開始と終了をプロット
	auto ds = new long[ dm + 1 ];
	foreach( stc; stcs )
	{
		ds[ stc[ 0 ] - 1 ]++;
		ds[ stc[ 1 ] ]--;
	}
	
	// 同時に放送される番組の最大数（＝必要な録画機の最大数）を集計
	auto ans = 0L;
	auto dt = 0L;
	foreach( d; ds )
	{
		dt += d;
		ans = max( ans, dt );
	}
	return ans;
}
