fun main(args: Array<String>) {
    val (N, C) = readInputLine().split(" ").map { it.toInt() }
    val recListTmp = mutableListOf<Triple<Int, Int, Int>>()
    
    for (i in 1..N) {
        val (s, t, c) = readInputLine().split(" ").map { it.toInt() }
        recListTmp.add(Triple(s, t, c))
    }
    
    recListTmp.sortBy { it.first }
    recListTmp.sortBy { it.third }

    val recList = mutableListOf<Triple<Int, Int, Int>>()
    recList.add(recListTmp.first())
    
    for (r in recListTmp.drop(1)) {
        val lastElem = recList.last()
        if (lastElem.third == r.third && lastElem.second == r.first) {
            recList.removeAt(recList.lastIndex)
            recList.add(Triple(lastElem.first, r.second, r.third))
        } else {
            recList.add(r)
        }
    }

    val reserved = IntArray(100002 * 2)
    
    for (r in recList) {
        reserved[r.first * 2 - 1]++
        reserved[r.second * 2 + 1]--
    }
    
    for (i in 1 until 100002 * 2) {
        reserved[i] += reserved[i - 1]
    }
    
    println(reserved.max())
}

fun readInputLine(): String {
    return readLine()!!
}
