fun main(args: Array<String>) {
  val (n, c) = readLine()!!.split(" ").map { it.toInt() }
  val chList = (0..c).map { mutableListOf<Pair<Int, Int>>() }

  for (i in 0 until n) {
    val (s, t, c) = readLine()!!.split(" ").map { it.toInt() }
    chList[c]!!.add(s to t)
  }

//  println(chList)

  val mergedChList = (0..c).map { mutableListOf<Pair<Int, Int>>() }
  for (i in 1..c) {
    val ch = chList[i].sortedBy { it.first }
    if (ch.isEmpty()) continue
//    print("ch>")
//    println(ch)
    mergedChList[i].add(ch[0])
    for (j in 1 until ch.size) {
      val last = mergedChList[i].last()
      if (last.second == ch[j].first) {
        mergedChList[i][mergedChList[i].lastIndex] = mergedChList[i][mergedChList[i].lastIndex].first to ch[j].second
      } else {
        mergedChList[i].add(ch[j])
      }
    }
  }

  val timeline = (0..100000).map { 0 }.toMutableList()

//  println(mergedChList)

  mergedChList.forEach {
    it.forEach {
      (it.first..it.second).forEach { timeline[it]++ }
    }
  }

  for (i in 0 until 100) {
//    println("$i ${timeline[i]}")
  }

  println(timeline.maxBy { it })
}
