import java.io.PrintWriter
import kotlin.comparisons.compareBy

fun main(args: Array<String>) {
    PrintWriter(System.out).use { out ->
        solve(out)
        out.flush()
    }
}

fun solve(out: PrintWriter) {
    val lastT = 100000 * 2 + 1
    val (n, c) = readIntegerList()
    val stsList = Array<MutableList<Pair<Int, Int>>>(30) { mutableListOf() }
    repeat(n) {
        val (s, t, c) = readIntegerList()
        stsList[c - 1].add(Pair(s * 10, t * 10))
    }

    val sNums = IntArray(lastT)
    val tNums = IntArray(lastT)
    for (sts in stsList) {
        sts.sortWith(compareBy<Pair<Int, Int>>({it.first!!}, {it.second!!}))
        sts.add(Pair(100000000, 100000000)) // 番兵
        var s = sts.first().first
        var t = sts.first().second
        for (st in sts) {
            if (st.first <= t) {
                t = st.second
            } else {
                sNums[(s - 5) / 5]++
                tNums[t / 5]++

                s = st.first
                t = st.second
            }
        }
    }
    val sums = IntArray(lastT + 1)
    for (i in 0 until lastT) {
        sums[i + 1] = sums[i] + sNums[i] - tNums[i]
    }
    println(sums.max()!!)
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)
fun readDoubleList() = readStringList().map(String::toDouble)
