import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = read.to!int;
	int cg = read.to!int;
	
	S[] xs;
	foreach(i; 0 .. n) xs ~= S(read.to!int, read.to!int, read.to!int);
	log("xs:", xs);
	
	Q[][int] ql;
	foreach(x; xs){
		if(x.c !in ql) ql[x.c] = [];
		ql[x.c] ~= Q(x.s, 1);
		ql[x.c] ~= Q(x.t, 0);
	}
	log("ql:", ql);
	
	int[] cs = ql.keys;
	foreach(c; cs) ql[c].sort!"a.isLess(b)"();
	log("cs:", cs);
	
	Q[] qs;
	foreach(c; cs){
		bool hasPended;
		Q pended;
		log("c:", c, "ql[c]:", ql[c]);
		foreach(q; ql[c]){
			if(hasPended){
				if(q.time == pended.time){
					hasPended = 0;
					continue;
				}
				else{
					qs ~= pended;
					qs ~= q;
					hasPended = 0;
				}
			}
			else pended = q, hasPended = 1;
		}
		if(hasPended) qs ~= pended;
		log("qs:", qs);
	}
	qs.sort!"a.isLess(b)"();
	log("qs:", qs);
	
	int worst = 0;
	int temp;
	foreach(q; qs){
		if(q.v == 1) temp += 1;
		else temp -= 1;
		worst = max(worst, temp);
	}
	
	worst.writeln;
}
struct S{
	int s, t;
	int c; 
}
struct Q{
	int time;
	int v; // 0=終了 1=開始
	bool isLess(Q q){
		if(this.time < q.time) return true;
		if(this.time > q.time) return false;
		if(this.v > q.v) return true;
		if(this.v < q.v) return false;
		return false;
	}
}
