#include <bits/stdc++.h>
using namespace std;
#define N 101000

int n,m,ans;
int st[N],ed[N],c[N],pre[N],res[N];

int main()
{
	scanf("%d%d",&n,&m);
	for (int i=1;i<=n;i++) scanf("%d%d%d",&st[i],&ed[i],&c[i]);
	
	for (int i=1;i<=m;i++)
	{
		memset(pre,0,sizeof(pre));
		for (int j=1;j<=n;j++) if (c[j]==i) pre[st[j]]++,pre[ed[j]+1]--;
		for (int j=1;j<=100000;j++) pre[j]+=pre[j-1];
		for (int j=1;j<=100000;j++) if (pre[j]>0) res[j]++;
	}
	for (int i=1;i<=100000;i++) ans=max(ans,res[i]);
	printf("%d\n",ans);
	return 0;
}