fun main(args: Array<String>) {
    val (N, C) = readLine()!!.split(" ").map { it.toInt() }
    val maxT = 100000
    val onAirTVCounts = Array(C + 1, { IntArray(maxT + 1) })
    onAirTVCounts.forEach {
        it.fill(0)
    }
    // This is not correct
    // See http://wk1080id.hatenablog.com/entry/2018/01/17/020356
    val tvInfo = mutableListOf<Triple<Int, Int, Int>>()
    (1..N).forEach {
        val (s, t, c) = readLine()!!.split(" ").map { it.toInt() }
        tvInfo.add(Triple(s, t, c))
    }

    val global = IntArray(maxT + 1)
    global.fill(0)
    (1 .. C).forEach {currentC ->
        // On each chaneel, imos method
        tvInfo.forEach {
            val (s, t, c) = it
            if (c == currentC) {
                onAirTVCounts[currentC][s - 1]++
                onAirTVCounts[currentC][t]--
            }
        }

        (0 until maxT).forEach {
            onAirTVCounts[currentC][it+1] += onAirTVCounts[currentC][it]
        }
        onAirTVCounts[currentC].forEachIndexed { index, value ->
            // consider as 1 tv show if it continuous
            if (value > 0) {
                global[index]++
            }
        }
    }
    println(global.max()!!)
}
