data class STC(val s: Int, val t: Int, val c: Int) {
    constructor(sc: List<Int>): this(sc[0] * 2 - 1, sc[1] * 2, sc[2])
}
fun main(args: Array<String>) {
    val (N, C) = listOfInt()
    val Stc = Array(N) { STC(listOfInt()) }
    val MAX = 200002
    val rec = IntArray(MAX)
    for (c in 1 .. C) {
        val tt = IntArray(MAX)
        for (stc in Stc)
            if (c == stc.c) { tt[stc.s] += 1; tt[stc.t] -= 1 }
        for (n in 1 until tt.size) tt[n] += tt[n - 1]
        for (n in 0 until tt.size) if (tt[n] > 0) rec[n] += 1
    }
//System.err.println(rec.joinToString())

    var ans = rec.max()!!
    println(ans)
}

fun next() = readLine()!!
fun nextInt(delta: Int = 0) = Integer.parseInt(next()) + delta
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }
fun listOfLong() = listOfString().map(String::toLong)
