
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val c = sc.nextInt()

    val stc = Array(n) { Triple(sc.nextInt(), sc.nextInt(), sc.nextInt()) }

    val p = stc.groupBy { it.third }
            .map { it.value.sortedBy { it.first } }
            .flatMap {
                it.fold(mutableListOf()) { acc: List<Triple<Int, Int, Int>>, tri ->
                    val last = acc.lastOrNull() ?: return@fold acc + tri

                    if (last.second == tri.first)
                        acc.dropLast(1) + last.copy(second = tri.second)
                    else
                        acc + tri
                }
            }

    var cur = 0
    val ret = (p.map { it.first to true } + p.map { it.second to false })
            .sortedBy { it.first }
            .map {
                if (it.second) {
                    cur += 1
                } else {
                    cur -= 1
                }
                cur
            }
            .max()

    println(ret)
}