object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, c = sc.nextInt()
  val sts = Array.fill(c)(List[(Int, Int)]())
  for (_ <- 1 to n) {
    val s, t, c = sc.nextInt() - 1
    sts(c) ::= (s, t)
  }

  def merge(st: List[(Int, Int)]): List[(Int, Int)] = {
    var res = List[(Int, Int)]()
    var last = -1
    for ((s, t) <- st) {
      if (last == s) {
        res = (res.head._1, t) :: res.tail
      } else {
        res ::= (s, t)
      }
      last = t
    }
    res
  }

  val st = sts.flatMap(st => merge(st.sorted))
  val a = Array.fill(100001)(0)
  for ((s, t) <- st) {
    a(s) += 1
    a(t+1) -= 1
  }
  val ans = a.scanLeft(0)(_ + _).max
  println(ans)
}
