#include <iostream>
#include <set>

#define maxN 100010

int main()
{
	std::set<std::pair<int,int>> set;
	int up[maxN]={0},down[maxN]={0},ss[maxN],ts[maxN],cs[maxN],max=0,n,c,count=0;
	std::cin>>n>>c;
	for (int i=0;i<n;++i)
	{
		std::cin>>ss[i]>>ts[i]>>cs[i];
		
		set.insert(std::make_pair(ts[i], cs[i]));
	}
	
	for (int i=0;i<n;++i)
	{
		if (set.count(std::make_pair(ss[i],cs[i])))
		{
			--down[ss[i]];
			--up[ss[i]];
		}
		++up[ss[i]];
		++down[ts[i]];
	}
	for (int i=0;i<=100000;++i)
	{
		count+=up[i];
		max=std::max(max,count);
		count-=down[i];
	}
	std::cout<<max;
}