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

  int n, c;
  rd(n, c);
  struct T {
    int l, r, c;
  }

  auto a = new T[][](c);
  foreach (_; 0 .. n) {
    int l, r, ci;
    rd(l, r, ci);
    a[ci - 1] ~= T(l, r, ci);
  }
  T[] b;
  foreach (i; 0 .. c) {
    if (a[i].length > 0) {
      a[i].sort!"a.l<b.l";
      int l = a[i][0].l, r = a[i][0].r;
      foreach (j; 1 .. a[i].length) {
        if (r == a[i][j].l) {
          r = a[i][j].r;
        }
        else {
          b ~= T(l, r, i);
          l = a[i][j].l;
          r = a[i][j].r;
        }
      }
      b ~= T(l, r, i);
    }
  }
  b.sort!"a.r==b.r ? a.l<b.l : a.r<b.r";
  int[] rs;
  foreach (el; b) {
    bool found = false;
    foreach (ref r; rs) {
      if (r < el.l) {
        found = true;
        r = el.r;
        break;
      }
    }
    if (!found) {
      rs ~= el.r;
    }
  }
  writeln(rs.length);
}

void rd(T...)(ref T x) {
  import std.stdio : readln;
  import std.string : split;
  import std.conv : to;

  auto l = readln.split;
  assert(l.length == x.length);
  foreach (i, ref e; x)
    e = l[i].to!(typeof(e));
}
