void main(){
  import std.stdio, std.string, std.conv, std.algorithm;
  import std.typecons;

  int n, k; rd(n, k);
  auto a=new int[](n), b=new int[](n), c=new int[](n);
  foreach(i; 0..n) rd(a[i], b[i], c[i]);

  alias T=Tuple!(int, "s", int, "t");
  auto seq=new T[][](k, 0);
  foreach(i; 0..n){
    seq[c[i]-1]~=T(a[i], b[i]);
  }

  auto seq2=new T[][](k, 0);
  foreach(i; 0..k)if(seq[i].length>0){
    sort(seq[i]);
    T[] tmp; tmp~=seq[i][0];
    for(int j=1; j<seq[i].length; j++){
      if(tmp[$-1].t==seq[i][j].s) tmp[$-1].t=seq[i][j].t;
      else tmp~=seq[i][j];
    }
    seq2[i]~=tmp;
  }

  auto sum=new int[](2*100005);
  foreach(i; 0..k)foreach(e; seq2[i]){
    sum[e.s*2-1]++; sum[e.t*2]--;
  }
  foreach(i; 1..(sum.length)) sum[i]+=sum[i-1];

  writeln(reduce!(max)(sum));

}

void rd(T...)(ref T x){
  import std.stdio, std.string, std.conv;
  auto l=readln.split;
  assert(l.length==x.length);
  foreach(i, ref e; x){
    e=l[i].to!(typeof(e));
  }
}
void wr(T...)(T x){
  import std.stdio;
  foreach(e; x) stderr.write(e, " ");
  stderr.writeln;
}